Programmierung 2 Object-Oriented Programming with Java Prof. O. Nierstrasz Sommersemester 2006.

Slides:



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

Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
©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.
General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
OORPT Object-Oriented Reengineering Patterns and Techniques 7. Problem Detection Prof. O. Nierstrasz.
Software Engineering and Design Principles Chapter 1.
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.
© Oscar Nierstrasz ST — Smalltalk Basics 2.1 Change sets  Make sure your changes are logged to a new change set.
The Software Composition Group Prof. O. Nierstrasz
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.
13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.
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.
Stéphane Ducasse6.1 Essential Concepts Why OO? What is OO? What are the benefits? What are the KEY concepts? Basis for all the lectures.
© Oscar Nierstrasz ST — Smalltalk Basics 2.1 Change sets  Make sure your changes are logged to a new change set.
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.
9. Guidelines, Idioms and Patterns. © O. Nierstrasz P2 — Guidelines, Idioms and Patterns 9.2 Guidelines, Idioms and Patterns Overview  Programming style:
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.
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.
Itntroduction to UML, page 1 Introduction to UML.
Programmierung 2 Object-Oriented Programming with Java 1. Introduction Prof. O. Nierstrasz Spring Semester 2010.
© 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:  …
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Programmierung 2 Object-Oriented Programming with Java Prof. O. Nierstrasz Sommersemester 2005.
UML and Object Oriented Concepts
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.
CSCI-383 Object-Oriented Programming & Design Lecture 9.
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
BTS430 Systems Analysis and Design using UML Design Patterns.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
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.
© 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.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
S.Ducasse Stéphane Ducasse 1 Essential OO Concepts Stéphane Ducasse.
1 Unified Modeling Language, Version 2.0 Chapter 2.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Basic Characteristics of Object-Oriented Systems
ISBN Chapter 12 Support for Object-Oriented Programming.
Slide 1 Unified Modeling Language, Version 2.0 Object-Oriented SAD.
Object Oriented Systems Design
Design Patterns: MORE Examples
MPCS – Advanced java Programming
Systems Analysis and Design With UML 2
Introduction to Design Patterns
Systems Analysis and Design With UML 2
Presentation transcript:

Programmierung 2 Object-Oriented Programming with Java Prof. O. Nierstrasz Sommersemester 2006

© O. Nierstrasz P2 — Introduction 1.2 P2 — Object-Oriented Programming Lecturer: Prof. Oscar Nierstrasz Schützenmattstr. 14/103 Tel: Assistants: Orla Greevy Michael Pfeuti, Lea Hänsenberger WWW: (includes full examples)

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

© O. Nierstrasz P2 — Introduction 1.4 Schedule 1. Introduction 2. Design by Contract 3. A Testing Framework 4. Debugging and Tools 5. Iterative Development 6. Inheritance and Refactoring 7. GUI Construction 8. Clients and Servers 9. Guidelines, Idioms and Patterns 10. A bit of C A bit of Smalltalk 12. Common Errors, a few Puzzles 13. Final Exam

© O. Nierstrasz P2 — Introduction 1.5 What is the hardest part of programming?

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

© O. Nierstrasz P2 — Introduction 1.7 How can we simplify programming?

© O. Nierstrasz P2 — Introduction 1.8 Key insights Real programs change! Development is incremental Design is iterative

© O. Nierstrasz P2 — Introduction 1.9 What is Object-Oriented Programming?  Encapsulation —Abstraction & information hiding  Composition —Nested objects  Distributing responsibility —Separation of concerns  Message passing —Delegating responsibility  Inheritance —Conceptual hierarchy, polymorphism and reuse

© O. Nierstrasz P2 — Introduction 1.10 A procedural design Problem: compute the total area of a set of geometric shapes public static long sumShapes(Shape shapes[]) { long sum = 0; for (int i=0; i<shapes.length; i++) { switch (shapes[i].kind()) { case Shape.RECTANGLE:// a class constant sum += shapes[i].rectangleArea(); break; case Shape.CIRCLE: sum += shapes[i].circleArea(); break;... // more cases } return sum; } public static long sumShapes(Shape shapes[]) { long sum = 0; for (int i=0; i<shapes.length; i++) { switch (shapes[i].kind()) { case Shape.RECTANGLE:// a class constant sum += shapes[i].rectangleArea(); break; case Shape.CIRCLE: sum += shapes[i].circleArea(); break;... // more cases } return sum; }

© O. Nierstrasz P2 — Introduction 1.11 An object-oriented approach A typical object-oriented solution: public static long sumShapes(Shape shapes[]) { long sum = 0; for (int i=0; i<shapes.length; i++) { sum += shapes[i].area(); } return sum; } public static long sumShapes(Shape shapes[]) { long sum = 0; for (int i=0; i<shapes.length; i++) { sum += shapes[i].area(); } return sum; } What are the advantages and disadvantages of the two solutions?

© O. Nierstrasz P2 — Introduction 1.12 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!

© O. Nierstrasz P2 — Introduction 1.13 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

© O. Nierstrasz P2 — Introduction 1.14 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

© O. Nierstrasz P2 — Introduction 1.15 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

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

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

© O. Nierstrasz P2 — Introduction 1.18 Refactoring “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 Common refactoring operations:  Rename methods, variables and classes  Redistribute responsibilities  Factor out helper methods  Push methods up or down the hierarchy  Extract class  …

© O. Nierstrasz P2 — Introduction 1.19 Design Patterns “a general repeatable solution to a commonly-occurring problem in software design.” — wikipedia.org 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

© O. Nierstrasz P2 — Introduction 1.20 Programming Tools Know your tools! —Version control system — e.g., cvs, rcs —Build tools — e.g., ant, make —Testing framework — e.g., Junit —Debuggers — e.g., jdb —Profilers — e.g., java -prof —Document generation — e.g., javadoc

© O. Nierstrasz P2 — Introduction 1.21 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.

© O. Nierstrasz P2 — Introduction 1.22 History

© O. Nierstrasz P2 — Introduction 1.23 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?

© O. Nierstrasz P2 — Introduction 1.24 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?

© O. Nierstrasz P2 — Introduction 1.25 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. 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.