Object Design II: Design Patterns

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

CS590L - Lecture 6 1 CS590L Distributed Component Architecture References: - E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of.
Chapter 8, Object Design Reuse and Patterns II Using UML, Patterns, and Java Object-Oriented Software Engineering.
Chapter 6: Using Design Patterns
Chapter 8, Object Design Introduction to Design Patterns
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
CS350/550 Software Engineering Lecture 1. Class Work The main part of the class is a practical software engineering project, in teams of 3-5 people There.
Software Engineering I Object-Oriented Design Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science.
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Chapter 8, Object Design Reuse and Patterns II Using UML, Patterns, and Java Object-Oriented Software Engineering.
Design Patterns Trends and Case Study John Hurst June 2005.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 1, Introduction to Software Engineering.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Using UML, Patterns, and Java Object-Oriented Software Engineering Object Design II: Design Patterns Bernd Bruegge Applied Software Engineering Technische.
ISP666 MVC & Design Patterns. Outline Review Event Programming Model Model-View-Controller Revisit Simple Calculator Break Design Patterns Exercise.
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
CSC 395 – Software Engineering Lecture 13: Object-Oriented Analysis –or– Let the Pain Begin (At Least I’m Honest!)
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
ECE450S – Software Engineering II
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 8, Object Design: Introduction to Design Patterns.
Introduction to Design Patterns Part 1. © Lethbridge/Laganière 2001 Chapter 6: Using design patterns2 Patterns - Architectural Architectural Patterns:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Presented by FACADE PATTERN
Chapter 8 Object Design: Reuse and Patterns.
Review of last class Software Engineering Modeling Problem Solving
Chapter 8 Object Design: Reuse and Patterns 2.
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And Created.
Design Patterns: MORE Examples
Software Design Refinement Using Design Patterns
Object-Oriented Analysis and Design
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
Chapter 8, Object Design Introduction to Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Pertemuan 08 Design Patterns & Anti-Patterns
Introduction to Design Patterns
Design Patterns.
Instructor: Dr. Hany H. Ammar
Chapter 8 Object Design: Reuse and Patterns 2.
Chapter 8, Design Patterns Bridge
OBJECT RELATIONSHIPS, ATTRIBUTES, AND METHODS
Chapter 8 Object Design: Reuse and Patterns.
Chapter 8, Object Design Reuse and Patterns II
Chapter 6, System Design Design Patterns
Presented by Igor Ivković
Chapter 6: Using Design Patterns
Chapter 8, Object Design Introduction to Design Patterns
Chapter 8, Object Design Introduction to Design Patterns
Design Patterns A Case Study: Designing a Document Editor
Introduction to Design Patterns Part 1
Chapter 1, Introduction to Software Engineering
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
OBJECT ARCHITECTURE DESIGN
Chapter 8, Design Patterns Composite
Software Design Lecture : 35.
Informatics 122 Software Design II
Chapter 8, Design Patterns Introduction
Composite Design Pattern By Aravind Reddy Patlola.
Presented by Igor Ivković
Chapter 8 - Design Strategies
Chapter 8, DesignPatterns Facade
Presentation transcript:

Object Design II: Design Patterns Bernd Bruegge Applied Software Engineering Technische Universitaet Muenchen

What is this? 1.Nf3 d5 2.c4 c6 3.b3 Bf5 4.g3 Nf6 5.Bg2 Nbd7 6.Bb2 e6 7.O-O Bd6 8.d3 O-O 9.Nbd2 e5 10.cxd5 cxd5 11.Rc1 Qe7 12.Rc2 a5 13.a4 h6 14.Qa1 Rfe8 15.Rfc1 This is a fianchetto! The fianchetto is one of the basic building-blocks of chess thinking.

Fianchetto (Reti-Lasker) The diagram is from Reti-Lasker, New York 1924. We can see that Reti has allowed Lasker to occupy the centre but Rtei has fianchettoed both Bishops to hit back at this, and has even backed up his Bb2 with a Queen on a1!

Is this a good Object Model? public interface SeatImplementation { public int GetPosition(); public void SetPosition(int newPosition); } public class AimSeat implements SeatImplementation { public int GetPosition() { // actual call to the AIM simulation system …. public class SARTSeat implements SeatImplementation { // actual call to the SART seat simulator ... Not quite But it depends….

A Game: Get-15 The game starts with nine numbers 1,2,3,4,5,6,7,8 and 9 You and your opponent take alternate turns, each taking a number Each number can be taken only once: If you opponent has selected a number, you can no longer take it The first person to have any three numbers that total 15 wins the game Example: You: 1 5 3 8 Opponent: 6 9 7 2 Opponent Wins!

Characteristics of Get-15 Hard to play The game is especially hard, if you are not allowed to write anything down Why? All the numbers must be scanned to see if you have won/lost It is hard to see what the opponent will take if you take a certain number The choice of the next number depends on all the previous numbers (your and your opponent’s numbers) Not easy to devise an simple strategy.

Another Game: Tic-Tac-Toe Source: http://boulter.com/ttt/index.cgi

A Draw Sitation

Strategy for determining a winning move

Winning Situations for Tic-Tac-Toe Patterns

Tic-Tac-Toe is “Easy” Why? Reduction of complexity through patterns and symmetry Patterns: Knowing the following three patterns, the player can anticipate the opponents move. Symmetry: The player needs to remember only these three patterns to deal with 8 different game situations The player needs to memorize only 3 opening moves and their responses.

Get-15 and Tic-Tac-Toe are identical problems Any sequence of three numbers that wins the Get-15 game also wins at Tic-Tac-Toe Any Tic-Tac-Toe solution is also a solution the to Get-15 problem To see the relationship between the two games, we simply arrange the 9 digits into the following pattern . 8 1 6 3 5 7 4 9 2

You: Opponent: 1 5 3 8 6 9 7 2 8 1 6 3 5 7 4 9 2 8 1 6 3 5 7 4 9 2

Design patterns keep the system model simple. During object modeling we do many transformations and changes to the object model It is important to make sure the system model stays simple during these model transformations After all, the goal of a model is to be an abstraction, that is, a simplification, not a complication Design patterns keep the system model simple.

Heuristics for Good Models Modeling must address our mental limitations: Our short-term memory has only limited capacity (7+-2) Good models deal with this limitation, because … … they do not tax the mind A good model requires a minimal mental effort to understand … they reduce complexity Use of patterns Use of symmetries … they use abstractions Taxonomies … they have organizational structure Memory limitations are overcome with an appropriate representation (“natural model”).

Outline of the Lecture Two games Heuristics for good models Patterns and symmetry help to win the game Heuristics for good models Reducing the complexity of models Patterns covered in this lecture Composite: Model dynamic aggregates Facade: Interfacing to subsystems Adapter: Interfacing to existing systems (legacy systems) Bridge: Interfacing to existing and future systems Next lecture (January 8) Factory and Abstract Factory Proxy Observer Strategy

Review: Design pattern A design pattern is… …a reusable template for solving a recurring design problem Basic idea: Don’t re-invent the wheel! … design knowledge Knowledge on a higher level than classes, algorithms or data structures (linked lists, binary trees...) Lower level than application frameworks …an example of modifiable design Learning how to design starts by studying other designs.

Why are modifiable designs important? A modifiable design… …enables an iterative and incremental development concurrent development risk management flexibility to change … minimizes the introduction of new problems when fixing old ones … allows to easily add more functionality after the delivery of the system

What makes a design modifiable? Low coupling and high cohesion Clear dependencies Explicit assumptions How do design patterns help? They are generalized from existing systems They provide a shared vocabulary to designers They provide examples of modifiable designs Abstract classes Delegation

What is common between these definitions? Definition Software System A software system consists of subsystems which are either other subsystems or collection of classes Definition Software Lifecycle A software lifecycle consists of a set of development activities which are either other actitivies or collection of tasks.

What is common between these definitions? Definition Software System A software system consists of subsystems which are either other subsystems or collection of classes Composite: Subsystem (A software system consists of subsystems which consists of subsystems, which consists of subsystems, which...) Leaf node: Class Definition Software Lifecycle A software lifecycle consists of a set of development activities which are either other actitivies or collection of tasks Composite: Activity (A software lifecycle consists of activities which consist of activities, which consist of activities, which....) Leaf node: Task.

Introducing the Composite Pattern Tree structures that represent part-whole hierarchies with arbitrary depth and width can be used in the solution of many problems The Composite Pattern lets a client treat individual objects and compositions of these objects uniformly Client Component Operation() * Leaf Operation() Composite Operation() AddComponent() RemoveComponent() GetChildren() Children

Modeling a Software System with a Composite Pattern User Software System * Class Subsystem Children

Modeling the Software Lifecycle with a Composite Pattern Manager Software Lifecycle * Task Activity Children

The Composite Patterns models Dynamic Aggregates Fixed Structure: Car * * Battery Engine Doors Wheels Organization Chart (variable aggregate): * School * What you are seeing on this slide are what I would like to call patterns for analysis. A pattern is a recurring theme, something once you get used to see something this way, allows you to very fast understand a situation. It is well known, that if you show a set of chess positions of middle games tochess masters and non chess players, that chess masters are able to reconstruct these games without any effort. However, if you give them random chess configurations, chess masters are about as bad as non-chess players in reconstructing the boards. This tells you about the value of patterns. I would like you to learn about these aggregation patterns. In fact, I challenge you to see for your team and subsystem, if any of the analysis problems you face, can be cast in terms of one of the 3 patterns above. University Department Dynamic tree (recursive aggregate): Program Composite Pattern * * Block Compound Simple Statement Statement

Graphic Applications use the Composite Pattern The Graphic Class represents both primitives (Line, Circle) and containers (Picture). Client Graphic Draw() Circle Picture Add(Graphic g) RemoveGraphic) GetChild(int) Children Line *

The Java‘s AWT library can be modeled with the component pattern Graphics Component Button TextField Label * TextArea Text Container add(Component c) paint(Graphics g) getGraphics()

Reducing the Complexity of Models Modeling is about communication To a human being as well as to a tool To communicate a complex model to a human being we use navigation and reduction of complexity Navigate through the model so the user can follow it Start with a very simple model Identify the key abstractions Then decorate the model with additional classes To reduce the complexity of the model further Look for inheritance (taxonomies) If the model is too complex, taxonomies should be placed in separate UML packages Then identify or introduce patterns in the model Make sure to use the name of the patterns. We do not simply use a snapshot from the CASE tool and dump it in front of the user If the model is too complex, taxonomies should be placed in separate UML packages. Only the superclass should stay in the top level view of the model

How to reduce the Complexity of the Model Look for the key abstractions Project, Outcome, Schedule, Work, Resource Identify patterns: For example, the project model has 3 composite patterns Find all the application domain taxonomies Start with the taxonomies for the key abstractions Key abstractions, patterns and/or taxonomies are candidates for separate UML packages. *

1. Find the Key Abstractions in the Model This model is already much more complex than the model shown on the previous slide. Its purpose is still for communication only. Because it already has quite a number of abstractions, It can only be understood if we communicate the model well to the user. We can do this by navigating through the model and highlight basic abstractions and typical patterns. For example, we can highlight the basic abstraction (the ones used in the previous slide) <<Proceed to first animation>> and tell the listener that these are the abstraction used in the previous slide (to make the point more clear, the instructor can move once more to the previous slide) To reduce the complexity of the model, the instructor can then point out that Work Product, Task and Participant all are now basic leaves in a composite pattern. <<Proceed to the next animation, show the use of the composite patterns>>. To reduce the complexity even further, the instructor finally points out the use of inheritance for the taxonomies (Resource, Staff, Work Product and Activity) Given these three tips, the students should be able to understand the model themselves.

Key Abstractions in the Project Model Outcome Schedule Work Resource

2. Find Patterns used in the Model Composite Patterns This model is already much more complex than the model shown on the previous slide. Its purpose is still for communication only. Because it already has quite a number of abstractions, It can only be understood if we communicate the model well to the user. We can do this by navigating through the model and highlight basic abstractions and typical patterns. For example, we can highlight the basic abstraction (the ones used in the previous slide) <<Proceed to first animation>> and tell the listener that these are the abstraction used in the previous slide (to make the point more clear, the instructor can move once more to the previous slide) To reduce the complexity of the model, the instructor can then point out that Work Product, Task and Participant all are now basic leaves in a composite pattern. <<Proceed to the next animation, show the use of the composite patterns>>. To reduce the complexity even further, the instructor finally points out the use of inheritance for the taxonomies (Resource, Staff, Work Product and Activity) Given these three tips, the students should be able to understand the model themselves.

Composite Patterns in the Project Model Staff * Organizational Unit Partici- pant Activity * Work Task Set of Work Products * Outcome Work product

3. Find the Taxonomies used in the Model This model is already much more complex than the model shown on the previous slide. Its purpose is still for communication only. Because it already has quite a number of abstractions, It can only be understood if we communicate the model well to the user. We can do this by navigating through the model and highlight basic abstractions and typical patterns. For example, we can highlight the basic abstraction (the ones used in the previous slide) <<Proceed to first animation>> and tell the listener that these are the abstraction used in the previous slide (to make the point more clear, the instructor can move once more to the previous slide) To reduce the complexity of the model, the instructor can then point out that Work Product, Task and Participant all are now basic leaves in a composite pattern. <<Proceed to the next animation, show the use of the composite patterns>>. To reduce the complexity even further, the instructor finally points out the use of inheritance for the taxonomies (Resource, Staff, Work Product and Activity) Given these three tips, the students should be able to understand the model themselves.

Step 4: Package based on Key Abstractions Project Project Outcome Schedule Work Resource

Step 4 continued: Additional Packages based on Patterns Outcome Work Organization Staff * Organizational Unit Partici- pant Activity * Work Task Set of Work Products * Outcome Work product

Step 4 continued: Additional UML Packages based on Taxonomies Resource Resource This model is already much more complex than the model shown on the previous slide. Its purpose is still for communication only. Because it already has quite a number of abstractions, It can only be understood if we communicate the model well to the user. We can do this by navigating through the model and highlight basic abstractions and typical patterns. For example, we can highlight the basic abstraction (the ones used in the previous slide) <<Proceed to first animation>> and tell the listener that these are the abstraction used in the previous slide (to make the point more clear, the instructor can move once more to the previous slide) To reduce the complexity of the model, the instructor can then point out that Work Product, Task and Participant all are now basic leaves in a composite pattern. <<Proceed to the next animation, show the use of the composite patterns>>. To reduce the complexity even further, the instructor finally points out the use of inheritance for the taxonomies (Resource, Staff, Work Product and Activity) Given these three tips, the students should be able to understand the model themselves.

Patterns are not the cure for everything What is wrong in the following pictures?

Summary Design patterns are template solutions for common design problems such as separating an interface from a number of alternate implementations Accessing a set of legacy classes protecting a caller from changes associated with specific platforms A design pattern consists of a small number of classes uses delegation and inheritance provides a modifiable design solution These classes can be adapted and refined for the specific system under construction To provide the reuse of existing solutions Customization of the system.

Additional Readings E. Gamma et.al., Design Patterns, 1994. M. Fowler, Analysis Patterns: Reusable Object Models, 1997 F. Buschmann et. Al., Pattern-Oriented Software Architecture: A System of Patterns, 1996 T. J. Mowbray & R. C. Malveau, CORBA Design Patterns, 1997 S. W. Ambler, Process Patterns: Building Large-Scale Systems Using Object Technology, 1998. Dependency management: P. Feiler & W. Tichy, “Propagator: A family of patterns,” in Proceedings of TOOLS-23'97, Santa Barbara, CA, Aug, 1997. Configuration management: W. J. Brown et. Al., AntiPatterns and Patterns in Software Configuration Management, 1999.

Backup Slides

Notation used in the Design Patterns Book Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software, Addison Wesley, 1995 Based on OMT (a precursor to UML). Notational differences between the OMT notation and UML: Attributes come after the Operations Associations are called acquaintances Multiplicities are shown as solid circles Dashed line: Instantiation Association (Class can instantiate objects of associated class) (In UML it denotes a dependency) UML Note is called Dog-ear box (connected by dashed line to class operation): Pseudo-code implementation of operation.