Object Design II: Design Patterns

Similar documents
A Rapid Overview of UML

Topics in Object-Oriented Design Patterns

Using Design Patterns in Java Application Development

CISC 322 Software Architecture

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

Introduction and History

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

Course "Softwaretechnik" Book Chapter 8 Object Design: Reuse and Patterns

Design Patterns. An introduction

6.3 Patterns. Definition: Design Patterns

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

Design Patterns. Gunnar Gotshalks A4-1

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Object-Oriented Oriented Programming

Object Oriented Programming. Michał Bereta

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

Applying the Observer Design Pattern

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Introduction to Software Engineering: Object Design I Reuse & Patterns

Design patterns are partial solutions to common

Tuesday, October 4. Announcements

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

As a programmer, you know how easy it can be to get lost in the details

Applying the Decorator Design Pattern

Design Patterns. Definition of a Design Pattern

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Design patterns. OOD Lecture 6

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

An Introduction to Patterns

Design Patterns 2. Page 1. Software Requirements and Design CITS 4401 Lecture 10. Proxy Pattern: Motivation. Proxy Pattern.

Chapter 11, Testing, Part 2: Integration and System Testing

MVC. Model-View-Controller. Design Patterns. Certain programs reuse the same basic structure or set of ideas

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Applying the Factory Method Design Pattern

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Chapter 5, Analysis: Object Modeling

DESIGN PATTERN - INTERVIEW QUESTIONS

Chapter 8, Design Patterns Visitor

An Introduction to Patterns

Chapter 5, Analysis: Dynamic Modeling

L18.1 Introduction... 2

Summary of the course lectures

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Software Engineering Fall 2015 (CSC 4350/6350) TR. 5:30 pm 7:15 pm. Rao Casturi 09/29/2015

Design Patterns. Hausi A. Müller University of Victoria. Software Architecture Course Spring 2000

administrivia today UML start design patterns Tuesday, September 28, 2010

Software Engineering I (02161)

Design Patterns. CSC207 Fall 2017

Chapter 11, Testing, Part 2: Integration and System Testing

Object-Oriented Software Engineering Conquering Complex and Changing Systems. Chapter 6, System Design Lecture 1

Object-Oriented Design

Chapter 12 (revised by JAS)

Design Patterns. CSC207 Winter 2017

Software Eningeering. Lecture 9 Design Patterns 2

Design patterns generic models

Design Patterns Lecture 2

Crash course on design patterns

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

LECTURE NOTES ON DESIGN PATTERNS MCA III YEAR, V SEMESTER (JNTUA-R09)

Acknowledgements. Materials were borrowed from

Information systems modelling UML and service description languages

The following topics will be covered in this course (not necessarily in this order).

2.1 Design Patterns and Architecture (continued)

2.1 Design Patterns and Architecture (continued)

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

L23.1 Introduction... 2

Software Engineering Fall 2015 (CSC 4350/6350) TR. 5:30 pm 7:15 pm. Rao Casturi 11/03/2015

Chapter 4 Requirements Elicitation

Design Patterns. Bernd Bruegge. Carnegie Mellon University Department of Computer Science 15 October 1998

Design Patterns. "Gang of Four"* Design Patterns. "Gang of Four" Design Patterns. Design Pattern. CS 247: Software Engineering Principles

Adapter pattern. Acknowledgement: Freeman & Freeman

CS 247: Software Engineering Principles. Design Patterns

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Chapter 6 System Design: Decomposing the System

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

Software Engineering Fall 2014

Chapter 5, Analysis: Dynamic Modeling

Page 1. Dynamic Modeling. How do you find classes? Dynamic Modeling with UML. UML Interaction Diagrams. UML State Chart Diagram.

SOFTWARE ENGINEERING SOFTWARE DESIGN. Saulius Ragaišis.

Software Engineering - I An Introduction to Software Construction Techniques for Industrial Strength Software

An Expert System for Design Patterns Recognition

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

Details of Class Definition

The GoF Design Patterns Reference

EMBEDDED SYSTEMS PROGRAMMING Design Patterns

Lecture 13: Design Patterns

Software Engineering Fall 2015 (CSC 4350/6350) TR. 5:30 pm 7:15 pm. Rao Casturi 09/17/2015

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Advanced Object Oriented PHP

Chapter 2, Modeling with UML, Part 2

Design Patterns (Facade, Composite)

Pattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Design Patterns. CSC207 Fall 2017

Recitation 13. Software Engineering Practices and Introduction to Design Patterns

Object Oriented Software Engineering Practical Software Development Using Uml And Java

Transcription:

Object-Oriented Software Engineering Using UML, Patterns, and Java Object Design II: Design Patterns Bernd Bruegge Applied Software Engineering Technische Universitaet Muenchen

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! Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6

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 a simple strategy. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7

Another Game: Tic-Tac-Toe Source: http://boulter.com/ttt/index.cgi Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8

A Draw Situation Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9

Strategy for determining a winning move Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10

Winning Situations for Tic-Tac-Toe Winning Patterns Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11

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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12

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 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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13

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 Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14

Stays 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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15

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 ). Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16

Outline of the Lecture Two games 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 Factory and Abstract Factory Proxy Observer Strategy Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17

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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18

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 Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19

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 Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20

Recall: Finding Objects The hardest problems in object-oriented system development are: Identifying objects Decomposing the system into objects Requirements Analysis focuses on application domain: Object identification System Design addresses both, application and implementation domain: Subsystem identification Object Design focuses on implementation domain: Additional solution objects. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21

Recall: Techniques for Finding Objects Requirements Analysis Start with Use Cases. Identify participating objects Textual analysis of flow of events (find nouns, verbs,...) Extract application domain objects by interviewing client (application domain knowledge) Find objects by using general knowledge System Design Subsystem decomposition Try to identify architectural style Object Design Find additional objects by applying implementation domain knowledge Try to identify design patterns. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22

COMPOSITE PATTERN Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23

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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24

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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25

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 Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27

Modeling the Software Lifecycle with a Composite Pattern Manager Software Lifecycle Task Activity Children Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28

The Composite Patterns models Dynamic Aggregates Fixed Structure: Car Doors Wheels Battery Engine Organization Chart (variable aggregate): University School Department Dynamic tree (recursive aggregate): Composite Pattern Program Block Compound Statement Simple Statement Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29

Graphic Applications use the Composite Pattern The Graphic Class represents both primitives (Line, Circle) and containers (Picture). Client Graphic Draw() Line Draw() Circle Draw() Picture Draw() Add(Graphic g) RemoveGraphic) GetChild(int) Children Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31

The Java s AWT library can be modeled with the component pattern Graphics Component getgraphics() Text Component Button Label Container add(component c) paint(graphics g) TextField TextArea Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32

Reducing the Complexity of Models Modeling is about communication To a human being (être humain) 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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 33

Example: Modeling a Project Project Equipment Facility Resource Fund Outcome Schedule produces Organization Work Breakdown Structure des- Work cribespackage con- sumes Organizational Work respon- Unit sible plays depends for Role Set of Work Products Work Product Activity Task Participant Staff Internal Work Product Project Deliverable Project Function Department Team Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34

How to reduce the Complexity of the Model 1. Look for the key abstractions Project, Outcome, Schedule, Work, Resource 2. Identify patterns: For example, the project model has 3 composite patterns 3. Find all the application domain taxonomies Start with the taxonomies for the key abstractions 4. Key abstractions, patterns and/or taxonomies are candidates for separate UML packages. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35

1. Find the Key Abstractions in the Model Key Abstractions Project Equipment Facility Resource Fund Outcome Schedule produces Organization Work Breakdown Structure des- Work cribespackage con- sumes Organizational Work respon- Unit sible plays depends for Role Set of Work Products Work Product Activity Task Participant Staff Internal Work Product Project Deliverable Project Function Department Team Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36

Key Abstractions in the Project Model Project Outcome Schedule Work Resource Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37

2. Find Patterns used in the Model Project Equipment Facility Composite Patterns Outcome Schedule produces Resource Fund Organization Work Breakdown Structure des- Work cribespackage con- sumes Organizational Work respon- Unit sible plays depends for Role Set of Work Products Work Product Activity Task Participant Staff Internal Work Product Project Deliverable Project Function Department Team Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38

Composite Patterns in the Project Model Outcome Work Organizational Unit Set of Work Products Work product Activity Task Staff Participant Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39

3. Find the Taxonomies used in the Model Taxonomies Project Equipment Facility Resource Fund Outcome Schedule produces Organization Work Breakdown Structure des- Work cribespackage con- sumes Organizational Work respon- Unit sible plays depends for Role Set of Work Products Work Product Activity Task Participant Staff Internal Work Product Project Deliverable Project Function Department Team Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40

Step 4: Package based on Key Abstractions Project Project Outcome Schedule Work Resource Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41

Step 4 continued: Additional Packages based on Patterns Outcome Work Organization Outcome Work Organizational Unit Set of Work Products Work product Activity Task Staff Participant Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42

Step 4 continued: Additional UML Packages based on Taxonomies Resource Resource Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43

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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 51

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. Plus ludique : Head First Design Patterns A Brain-Friendly Guide By Bert Bates, Kathy Sierra, Eric Freeman, Elisabeth Robson Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 52

Backup Slides Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 53

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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 54