Programmierung 2 Object-Oriented Programming with Java 1. Introduction Prof. O. Nierstrasz Spring Semester 2010.

Slides:



Advertisements
Similar presentations
Software Engineering Key design concepts Design heuristics Design practices.
Advertisements

8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
12. Common Errors, a few Puzzles. © O. Nierstrasz P2 — Common Errors, a few Puzzles 12.2 Common Errors, a few Puzzles Sources  Cay Horstmann, Computing.
ESE Einführung in Software Engineering 6. Modeling Objects and Classes Prof. O. Nierstrasz.
ESE Einführung in Software Engineering 7. Modeling Behaviour Prof. O. Nierstrasz.
Introduction to Software Engineering 7. Modeling Behaviour.
A Brief Introduction. Acknowledgements  The material in this tutorial is based in part on: Concurrency: State Models & Java Programming, by Jeff Magee.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
OORPT Object-Oriented Reengineering Patterns and Techniques 7. Problem Detection Prof. O. Nierstrasz.
Object-Oriented Analysis and Design
Introduction To System Analysis and Design
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
Object-Oriented Reengineering Patterns and Techniques Prof. O. Nierstrasz Prof. S. Ducasse T.
12. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Roadmap  Summary: —Trends in programming paradigms  Research:...
ESE Einführung in Software Engineering N. XXX Prof. O. Nierstrasz Fall Semester 2009.
13. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Summary, Trends, Research...  Summary: functional, logic and object-oriented.
ESE Einführung in Software Engineering X. CHAPTER Prof. O. Nierstrasz Wintersemester 2005 / 2006.
Metamodeling Seminar X. CHAPTER Prof. O. Nierstrasz Spring Semester 2008.
Programmierung 2 Object-Oriented Programming with Java 1. Introduction Prof. O. Nierstrasz Spring Semester 2008.
Programmierung 2 Object-Oriented Programming with Java Prof. O. Nierstrasz Sommersemester 2006.
ESE Einführung in Software Engineering X. CHAPTER Prof. O. Nierstrasz Wintersemester 2005 / 2006.
© Wolfgang Pelz Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.
Programmierung 2 Object-Oriented Programming with Java Orla Greevy Sommersemester 2007.
N. XXX Prof. O. Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes.
SOS OOP Fall 2001 Object Oriented Programming in Java Week 1 Read a design Design a small program Extract a design Run a VAJ program Change that program,
12. Summary, Trends, Research. © O. Nierstrasz PS — Summary, Trends, Research Roadmap  Summary: —Trends in programming paradigms  Research:...
ESE Einführung in Software Engineering 6. Modeling Objects and Classes Prof. O. Nierstrasz.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.1 MakeMoney Corp. C*O of MakeMoney Corp. Our Vision  We invest in software  We do not know software 
OORPT Object-Oriented Reengineering Patterns and Techniques X. CHAPTER Prof. O. Nierstrasz.
CP — Concurrent Programming X. CHAPTER Prof. O. Nierstrasz Wintersemester 2005 / 2006.
12. eToys. © O. Nierstrasz PS — eToys 12.2 Denotational Semantics Overview:  … References:  …
Programmierung 2 Object-Oriented Programming with Java Prof. O. Nierstrasz Sommersemester 2005.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
UML and Object Oriented Concepts
Copyright © 2002, Systems and Computer Engineering, Carleton University Intro.ppt * Object-Oriented Software Development Unit 1 Course.
Object-Oriented Software Testing. C-S 5462 Object-Oriented Software Testing Research confirms that testing methods proposed for procedural approach are.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 1, Introduction to Software Engineering.
Introduction to Object-oriented programming and software development Lecture 1.
Objects and Components. The adaptive organization The competitive environment of businesses continuously changing, and the pace of that change is increasing.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
CSCI-383 Object-Oriented Programming & Design Lecture 9.
Implementing Design Patterns Using Java St. Louis Java Special Interest Group Eric M. Burke Object Computing, Inc. Presented on July 9, 1998 (updated July.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Slide 1 UML Review Chapter 2: Introduction to Object-Oriented Systems Analysis and Design with the Unified Modeling Language, Version 2.0 Alan Dennis,
Unified Modeling Language, Version 2.0
Introduction To System Analysis and Design
Design engineering Vilnius The goal of design engineering is to produce a model that exhibits: firmness – a program should not have bugs that inhibit.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
1 How to Design Frameworks -- Copyright 2005 by Ralph E. Johnson How to Develop Frameworks Ralph E. Johnson Dept. of Computer Science 1304 W. Springfield.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
Salman Marvasti Sharif University of Technology Winter 2015.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
Advanced Object-Oriented Design Patterns and Architectures Part One COEN396A John Xiao
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
Software Design 1.1 CPS 108, Spring 2006 l Object oriented programming and design, we'll use Java and C++  Language independent concepts including design.
1 Unified Modeling Language, Version 2.0 Chapter 2.
CMSC 345 Fall 2000 OO Design. Characteristics of OOD Objects are abstractions of real-world or system entities and manage themselves Objects are independent.
Basic Characteristics of Object-Oriented Systems
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Object Oriented Systems Design
MPCS – Advanced java Programming
Systems Analysis and Design With UML 2
Systems Analysis and Design With UML 2
Object-Orientated Programming
Presentation transcript:

Programmierung 2 Object-Oriented Programming with Java 1. Introduction Prof. O. Nierstrasz Spring Semester 2010

© Oscar Nierstrasz P2 — Introduction 1.2 P2 — Object-Oriented Programming Lecturer: Oscar Nierstrasz Assistants: Adrian Kuhn Niko Schwartz, Patrik Rauber WWW: scg.unibe.ch/teaching/p2

© Oscar Nierstrasz P2 — Introduction 1.3 Roadmap  Goals, Schedule  What is programming all about?  What is Object-Oriented programming?  Foundations of OOP  Why Java?  Programming tools, subversion

© Oscar Nierstrasz P2 — Introduction 1.4 Roadmap  Goals, Schedule  What is programming all about?  What is Object-Oriented programming?  Foundations of OOP  Why Java?  Programming tools, subversion

© Oscar Nierstrasz P2 — Introduction 1.5 Your Learning Targets Knowledge Skills + You understand requirements engineering, designing and implementing object-oriented software You can understand and create basic UML Diagrams You apply a Test-Driven Development process You use your IDE, Debugger efficiently and effectively You understand and can apply various DesignPatterns You can communicate and work in Teams

© Oscar Nierstrasz P2 — Introduction 1.6 The Big Picture P1 P2 DB DA ESEPSE … EI MMS

© Oscar Nierstrasz P2 — Introduction 1.7 Recommended Texts  Java in Nutshell: 5th edition, David Flanagan, O’Reilly,  An Introduction to Object-Oriented Programming, Timothy Budd, Addison-Wesley,  Object-Oriented Software Construction, Bertrand Meyer,Prentice Hall,  Object Design - Roles, Responsibilities and Collaborations, Rebecca Wirfs-Brock, Alan McKean, Addison-Wesley,  Design Patterns: Elements of Reusable Object-Oriented Software, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison Wesley, Reading, Mass.,  The Unified Modeling Language Reference Manual, James Rumbaugh, Ivar Jacobson, Grady Booch, Addison-Wesley, 1999

© Oscar Nierstrasz P2 — Introduction 1.8 Schedule 1. Introduction 2. Object-Oriented Design Principles 3. Design by Contract 4. A Testing Framework 5. Iterative Development 6. Debugging and Tools 7. Inheritance and Refactoring 8. GUI Construction 9. Guidelines, Idioms and Patterns 10. Advanced OO Design 11. A bit of C Guest Lecture — Einblicke in die Praxis 13. Common Errors, a few Puzzles 14. Final Exam

© Oscar Nierstrasz P2 — Introduction 1.9 Roadmap  Goals, Schedule  What is programming all about?  What is Object-Oriented programming?  Foundations of OOP  Why Java?  Programming tools, subversion

© Oscar Nierstrasz P2 — Introduction 1.10 What is the hardest part of programming?

© Oscar Nierstrasz P2 — Introduction 1.11 What constitutes programming?  Understanding requirements  Design  Testing  Debugging  Developing data structures and algorithms  User interface design  Profiling and optimization  Reading code  Enforcing coding standards ...

© Oscar Nierstrasz P2 — Introduction 1.12 Roadmap  Goals, Schedule  What is programming all about?  What is Object-Oriented programming?  Foundations of OOP  Why Java?  Programming tools, subversion

Programming is modeling © Oscar Nierstrasz Computational Thinking 13

© Oscar Nierstrasz P2 — Introduction 1.14 Encapsulation Composition Distribution of Responsibility Distribution of Responsibility Message Passing Inheritance Abstraction & Information Hiding Nested Objects Separation of concerns (e.g., HTML, CSS) Delegating responsibility Conceptual hierarchy, polymorphism and reuse What is Object-Oriented Programming?

© Oscar Nierstrasz P2 — Introduction 1.15 Procedural versus OO designs Problem: compute the total area of a set of geometric shapes public static void main(String[] args) { Picture myPicture = new Picture(); myPicture.add(new Square(3,3,3)); // (x,y,width) myPicture.add(new Rectangle(5,9,5,3));// (x,y,width,height) myPicture.add(new Circle(12,3,3)); // (x,y,radius) System.out.println("My picture has size " + myPicture.size()); } How to compute the size?

© Oscar Nierstrasz P2 — Introduction 1.16 Procedural approach: centralize computation double size() { double total = 0; for (Shape shape : shapes) { switch (shape.kind()) { case SQUARE: Square square = (Square) shape; total += square.width * square.width; break; case RECTANGLE: Rectangle rectangle = (Rectangle) shape; total += rectangle.width * rectangle.height; break; case CIRCLE: Circle circle = (Circle) shape; total += java.lang.Math.PI * circle.radius * circle.radius / 2; break; } return total; }

Object-oriented approach: distribute computation © Oscar Nierstrasz P2 — Introduction 1.17 double size() { double total = 0; for (Shape shape : shapes) { total += shape.size(); } return total; } What are the advantages and disadvantages of the two solutions? public class Square extends Shape {... public double size() { return width*width; }

© Oscar Nierstrasz P2 — Introduction 1.18 Roadmap  Goals, Schedule  What is programming all about?  What is Object-Oriented programming?  Foundations of OOP  Why Java?  Programming tools, subversion

© Oscar Nierstrasz P2 — Introduction 1.19 Object-Oriented Design in a Nutshell  Identify minimal requirements  Make the requirements testable  Identify objects and their responsibilities  Implement and test objects  Refactor to simplify design  Iterate!

© Oscar Nierstrasz P2 — Introduction 1.20 Responsibility-Driven Design  Objects are responsible to maintain information and provide services  A good design exhibits: —high cohesion of operations and data within classes —low coupling between classes and subsystems  Every method should perform one, well-defined task: —High level of abstraction — write to an interface, not an implementation

© Oscar Nierstrasz P2 — Introduction 1.21 Design by Contract  Formalize client/server contract as obligations  Class invariant — formalize valid state  Pre- and post-conditions on all public services —clarifies responsibilities —simplifies design —simplifies debugging

© Oscar Nierstrasz P2 — Introduction 1.22 Extreme Programming Some key practices:  Simple design —Never anticipate functionality that you “might need later”  Test-driven development —Only implement what you test!  Refactoring —Aggressively simplify your design as it evolves  Pair programming —Improve productivity by programming in pairs

© Oscar Nierstrasz P2 — Introduction 1.23 Testing  Formalize requirements  Know when you are done  Simplify debugging  Enable changes  Document usage

© Oscar Nierstrasz P2 — Introduction 1.24 Code Smells  Duplicated code  Long methods  Large classes  Public instance variables  No comments  Useless comments  Unreadable code  …

Refactoring © Oscar Nierstrasz P2 — Introduction 1.25 Common refactoring operations:  Rename methods, variables and classes  Redistribute responsibilities  Factor out helper methods  Push methods up or down the hierarchy  Extract class  … “Refactoring is the process of rewriting a computer program or other material to improve its structure or readability, while explicitly keeping its meaning or behavior.” — wikipedia.org “Refactoring is the process of rewriting a computer program or other material to improve its structure or readability, while explicitly keeping its meaning or behavior.” — wikipedia.org

© Oscar Nierstrasz P2 — Introduction 1.26 Design Patterns “a general repeatable solution to a commonly-occurring problem in software design.” Example  Adapter — “adapts one interface for a class into one that a client expects.” Patterns:  Document “best practice”  Introduce standard vocabulary  Ease transition to OO development But …  May increase flexibility at the cost of simplicity

© Oscar Nierstrasz P2 — Introduction 1.27 Roadmap  Goals, Schedule  What is programming all about?  What is Object-Oriented programming?  Foundations of OOP  Why Java?  Programming tools, subversion

© Oscar Nierstrasz P2 — Introduction 1.28 Why Java? Special characteristics  Resembles C++ minus the complexity  Clean integration of many features  Dynamically loaded classes  Large, standard class library Simple Object Model  “Almost everything is an object”  No pointers  Garbage collection  Single inheritance; multiple subtyping  Static and dynamic type-checking Few innovations, but reasonably clean, simple and usable.

© Oscar Nierstrasz P2 — Introduction 1.29 History

© Oscar Nierstrasz P2 — Introduction 1.30 Roadmap  Goals, Schedule  What is programming all about?  What is Object-Oriented programming?  Foundations of OOP  Why Java?  Programming tools, subversion

© Oscar Nierstrasz P2 — Introduction 1.31 Programming Tools Know your tools! —IDEs (Integrated Development Environment)— e.g., Eclipse, —Version control system — e.g., svn,cvs, rcs —Build tools — e.g., maven, ant, make —Testing framework — e.g., Junit —Debuggers — e.g., jdb —Profilers — e.g., java -prof, jip —Document generation — e.g., javadoc

© O. Nierstrasz P2 — Testing and Debugging 5.32 Version Control Systems A version control system keeps track of multiple file revisions:  check-in and check-out of files  logging changes (who, where, when)  merge and comparison of versions  retrieval of arbitrary versions  “freezing” of versions as releases  reduces storage space (manages sources files + multiple “deltas”)

© O. Nierstrasz P2 — Testing and Debugging 5.33 Version Control Version control enables you to make radical changes to a software system, with the assurance that you can always go back to the last working version.  When should you use a version control system?  Use it whenever you have one available, for even the smallest project! Version control is as important as testing in iterative development!

© Oscar Nierstrasz P2 — Introduction 1.34 What you should know!  What is meant by “separation of concerns”?  Why do real programs change?  How does object-oriented programming support incremental development?  What is a class invariant?  What are coupling and cohesion?  How do tests enable change?  Why are long methods a bad code smell?

© Oscar Nierstrasz P2 — Introduction 1.35 Can you answer these questions?  Why does up-front design increase risk?  Why do objects “send messages” instead of “calling methods”?  What are good and bad uses of inheritance?  What does it mean to “violate encapsulation”?  Why is strong coupling bad for system evolution?  How can you transform requirements into tests?  How would you eliminate duplicated code?  When is the right time to refactor your code?

© Oscar Nierstrasz P2 — Introduction 1.36 License > Attribution-ShareAlike 2.5 You are free: to copy, distribute, display, and perform the work to make derivative works to make commercial use of the work Under the following conditions: Attribution. You must attribute the work in the manner specified by the author or licensor. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above.