COMP 7700 – Introduction to Design Patterns1Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Chapter 6Introduction to Design Patterns3 Types:CreationalStructuralBehavioralCOMP 7700 – Introduction to Design Patterns2Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Process Phase Discussed in This ChapterRequirementsAnalysisDesignImplementationArchitectureFramework Detailed DesignxKey: = secondary emphasisx= main emphasisCOMP 7700 – Introduction to Design Patterns3Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Sample Design Goals and Ways toAccomplish Them Reusability, Flexibility, and Maintainabilityo Reuse flexible designso Keep code at a general levelo Minimize dependency on other classes Robustnesso Reuse reliable designso Reuse robust parts Sufficiency / Correctnesso Modularize designo Reuse trusted partsCOMP 7700 – Introduction to Design Patterns4Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.KitchenViewer InterfaceWallcabinetCounterFloorcabinetModern Classic Antique Arts & Craftsmenudisplay areastylesUse case page 1241. User clocks on the “wall cabinet” icon2. Application displays a wall cabinet in center of the work area3. User resizes the wall cabinet4. User drags the wall cabinet in the upperhalf of the work area5. User releases cursor6. Application places the wall cabinet in aposition in the upper half of the work area7. User clicks on the “floor cabinet” icon8. Application displays a floor cabinet in thecenter of the work area. ............COMP 7700 – Introduction to Design Patterns5Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.KitchenViewer Example Modern Classic Antique Arts & CraftsWall cabinetsFloor cabinetsCountertopCOMP 7700 – Introduction to Design Patterns6Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Selecting Antique Style Modern Classic Antique Arts & CraftsCOMP 7700 – Introduction to Design Patterns7Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.KitchenViewer Without Design PatternsKitchenClientrenderKitchen()FloorCabinet ModernWallCabinetModernFloorCabinet AntiqueFloorCabinetAntiqueWallCabinetWallCabinet COMP 7700 – Introduction to Design Patterns8Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.What are Design Patterns?• Design patterns are class combinations andaccompanying algorithms that fulfill commondesign purposes.• A design pattern expresses an idea rather than afixed class combination.COMP 7700 – Introduction to Design Patterns9Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Design Goal At Work: Flexibility Our design should be flexible enough toproduce any of several kitchen styles.COMP 7700 – Introduction to Design Patterns10Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.AntiqueKStylegetWallCabinet()getFloorCabinet()The Abstract Factory IdeaKitchenStylegetWallCabinet()getFloorCabinet()ModernKStylegetWallCabinet()getFloorCabinet()WallCabinet FloorCabinet AntiqueWallCabinet AntiqueFloorCabinetFloorCabinet getFloorCabinet(){ return new AntiqueFloorCabinet(); }……FloorCabinet getFloorCabinet(){ return new ModernFloorCabinet(); }COMP 7700 – Introduction to Design Patterns11Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Abstract Factory Design PatternApplied to KitchenViewerKitchenStylegetWallCabinet()getFloorCabinet()KitchengetWallCabinet()getFloorcabinet()ClientrenderKitchen( KitchenStyle )ModernKStylegetWallCabinet()getFloorCabinet()AntiqueKStylegetWallCabinet()getFloorCabinet()WallCabinet FloorCabinet ModernWallCabinetModernFloorCabinetAntiqueWallCabinetAntiqueFloorCabinet“reflecting polymorphism”COMP 7700 – Introduction to Design Patterns12Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Abstract Factory Design PatternStylegetComponentA()getComponentB()ClientdoOperation( Style myStyle )Style1getComponentA()getComponentB()Style2getComponentA()getComponentB()ComponentA ComponentBStyle1ComponentAStyle1ComponentBStyle2ComponentAStyle2ComponentBCollectionCOMP 7700 – Introduction to Design Patterns13Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Abstract Factory Design Pattern AlternativeStylegetComponentA()getComponentB()ClientdoOperation()Style1getComponentA()getComponentB()Style2getComponentA()getComponentB()ComponentA ComponentBStyle1ComponentAStyle1ComponentBStyle2ComponentAStyle2ComponentBCollection getComponentA()getComponentB()does not reference style directlydoOperation() takes noparametersCollection has methods for gettingthe various componentsCOMP 7700 – Introduction to Design Patterns14Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Design Patterns-- class combination and algorithm fulfilling a commondesign purpose.Key Concept: Creational Design Patterns -- used to create objects in flexible or constrained ways.Key Concept: Structural Design Patterns -- used to represent data structures such as trees, withuniform processing interfaces.Key Concept: Behavioral Design Patterns -- to capture behavior among objects. COMP 7700 – Introduction to Design Patterns15Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.Creational Design Patterns• Creational design patterns help us to designapplications involving collections of objects:– They allow the creation of several possible creationsfrom a single block of code such as:• Creating many versions of the collection at runtime• Constraining the objects created: for example, ensuringthat there is only one instance of its class• Creational design patterns discussed in nextlecture:– Factory– Abstract
View Full Document