object-Oriented Software Engineering Practical Software development using uml and Java Chapter 6: sing Design Patterns www.oseng.com
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns
6.1 Introduction to patterns The recurring aspects of designs are called designpatterns. a pattern is the outline of a reusable solution to a general problem encountered in a particular context Many of them have been systematically documented for all software developers to use A good pattern should be as general as possible -Contain a solution that has been proven to effectively solve the problem in the indicated context Studying patterns is an effective way to learn from the experience of others www.oseng.com O Lethbridge/Laganiere 2001 Chapter 6: Using design patterns
© Lethbridge/Laganière 2001 Chapter 6: Using design patterns 2 6.1 Introduction to Patterns The recurring aspects of designs are called design patterns. • A pattern is the outline of a reusable solution to a general problem encountered in a particular context • Many of them have been systematically documented for all software developersto use • A good pattern should —Be as general as possible —Contain a solution that has been proven to effectively solve the problemin the indicated context. Studying patterns is an effective way to learn from the experience of others
Pattern description Context: The general situation in which the pattern applies Proble a short sentence or two raising the main difficulty Forces The issues or concerns to consider when solving the problem Solution The recommended way to solve the problem in the given context ‘ to balance the forces Antipatterns: (Optional) Solutions that are inferior or do not work in this context Related patterns: (Optional) Patterns that are similar to this pattern References Who developed or inspired the pattern www.oseng.com O Lethbridge/Laganiere 2001 Chapter 6: Using design patterns
© Lethbridge/Laganière 2001 Chapter 6: Using design patterns 3 Pattern description Context: • The general situation in which the pattern applies Problem: —A shortsentence or two raising the main difficulty. Forces: • The issues or concernsto consider when solving the problem Solution: • The recommended way to solve the problemin the given context. —‘to balance the forces’ Antipatterns:(Optional) • Solutionsthat are inferior or do not work in this context. Related patterns: (Optional) • Patternsthat are similar to this pattern. References: • Who developed or inspired the pattern
6.2 The Abstraction-Occurrence pattern · Context -Often in a domain model you find a set of related objects occurrences -The members of such a set share common information but also differ from each other in important ways · Problen what is the best way to represent such sets of occurrences in a class diagram · Forces You want to represent the members of each set of occurrences without duplicating the common information www.oseng.com O Lethbridge/Laganiere 2001 Chapter 6: Using design patterns 4
© Lethbridge/Laganière 2001 Chapter 6: Using design patterns 4 6.2 The Abstraction-Occurrence Pattern • Context: —Often in a domain model you find a set of related objects (occurrences). —The members of such a set share common information - but also differ from each other in important ways. • Problem: —What is the best way to represent such sets of occurrences in a class diagram? • Forces: —You want to represent the members of each set of occurrences without duplicating the common information
Abstraction-Occurrence Solution Abstraction》 Occurrence》 TVSeries Episode series Name number producer title story Synopsis Title Librarylter barCode Number author publicationDate libofCongress www.oseng.com O Lethbridge/Laganiere 2001 Chapter 6: Using design patterns
© Lethbridge/Laganière 2001 Chapter 6: Using design patterns 5 Abstraction-Occurrence • Solution: TVSeries seriesName producer Episode number title storySynopsis * «Abstraction» «Occurrence» * Title name author LibraryItem barCodeNumber * isbn publicationDate libOfCongress
Abstraction-Occurrence Antipatterns: Libraryltem Librarvitem Title name na me name u tho auton au thol is bn publicati on Date oublicati on date publicati on Date libOfCongress li boc ongress li boiC ongress barco renumber barcodenumber Libraryltem GulliversTravels Moby Dick bar codenumber www.oseng.com O Lethbridge/Laganiere 2001 Chapter 6: Using design patterns 6
© Lethbridge/Laganière 2001 Chapter 6: Using design patterns 6 Abstraction-Occurrence Antipatterns: name author LibraryItem ba rCodeNumber is bn publicationDate libOfCongre ss Title name author LibraryItem ba rCodeNumber is bn publicationDate libOfCongre ss name author LibraryItem ba rCodeNumber is bn publicationDate libOfCongre ss GulliversTravels MobyDick
Abstraction-Occurrence Square variant Scheduledtrain SpecificTrain number date ScheduledLeg SpecificLeg scheduled DepTime actualDepTime scheduledarr time actualArr Time origIn destination Station www.oseng.com O Lethbridge/Laganiere 2001 Chapter 6: Using design patterns
© Lethbridge/Laganière 2001 Chapter 6: Using design patterns 7 Abstraction-Occurrence Square variant ScheduledTrain number SpecificTrain date * * * ScheduledLeg SpecificLeg actualDepTime * actualArrTime scheduledDepTime scheduledArrTime Station origin destination * *
6.3 The general hierarchy pattern · Context -Objects in a hierarchy can have one or more objects above them superiors and one or more objects below them(subordinates) Some objects cannot have any subordinates · Problen objects cannot have subordinates y of objects, in which some How do you represent a hierarchy orces You want a flexible way of representing the hierarchy that prevents certain objects from having subordinates -all the objects have many common properties and operations www.oseng.com O Lethbridge/Laganiere 2001 Chapter 6: Using design patterns 8
© Lethbridge/Laganière 2001 Chapter 6: Using design patterns 8 6.3 The General Hierarchy Pattern • Context: —Objects in a hierarchy can have one or more objects above them (superiors), - and one or more objects below them (subordinates). —Some objects cannot have any subordinates • Problem: —How do you represent a hierarchy of objects, in which some objects cannot have subordinates? • Forces: —You want a flexible way of representing the hierarchy - that prevents certain objects from having subordinates —All the objects have many common properties and operations
General hierarchy Node》 · Solution: 《 subordinate》 Non SuperiorNode》 SuperiorNode》 Employee supervises File Systemltemk contains SecretaryTechnician/[ Manager File Directory www.oseng.com O Lethbridge/Laganiere 2001 Chapter 6: Using design patterns
© Lethbridge/Laganière 2001 Chapter 6: Using design patterns 9 General Hierarchy • Solution: «subordinate» * «Node» «NonSuperiorNode» «SuperiorNode» * supervises Manager Employee Secretary Technician 0..1 0..1 * contains Directory FileSystemItem File 0..1
General Hierarch Antipattern Recording VideoRecoding AudioRecording MusicVideo JazzRecording ClassicalRecording Blues Recording RockRecordingl www.oseng.com O Lethbridge/Laganiere 2001 Chapter 6: Using design patterns
© Lethbridge/Laganière 2001 Chapter 6: Using design patterns 10 General Hierarchy Antipattern: MusicVideo JazzRecording ClassicalRecording BluesRecording RockRecording VideoRecoding AudioRecording Recording