Design PatternsAcknowledgementsMotivationDesign PatternBecoming a Chess MasterBecoming a Software Design MasterSlide 7ApplicationsCollaboration in the Observer PatternDesign Pattern DescriptionsDesign Pattern SpaceCategorize Design PatternsCategorization TermsClass ScopeExample Class ScopeClass StructuralClass BehavioralObject ScopeObject CreationalObject StructuralObject BehavioralObject Behavioral ExampleObject Structural ExampleCreational PatternsStructural Patterns:Behavioral PatternsBehavior Patterns (more)When to Use PatternsWhat Makes it a PatternBenefits of Design PatternsDrawbacks to Design PatternsSuggestions for Effective Pattern UseRRRDesign PatternsRRRAcknowledgementsMaterials based on a number of sources–D. Levine and D. Schmidt–R. Helm–Gamma et alRRRMotivation•Developing software is hard•Designing reusable software is more challenging–finding good objects and abstractions–flexibility, modularity, elegance reuse–takes time for them to emerge, trial and error•Successful designs do exist–exhibit recurring class and object structuresRRRDesign Pattern•Describes recurring design structure–names, abstracts from concrete designs–identifies classes, collaborations, responsibilities–applicability, trade-offs, consequencesRRRBecoming a Chess Master•First learn rules and physical requirements–e.g., names of pieces, legal movements, chess board geometry and orientation, etc.•Then learn principles–e.g, relative value of certain pieces, strategic value of center squares, power of a threat, etc.•To become a Master of chess, one must study the games of other masters–These games contain patterns that must be understood, memorized, and applied repeatedly.•There are hundreds of these patternsRRRBecoming a Software Design Master•First learn rules–e.g., algorithms, data structures, and languages of software.•Then learn principles–e.g., structured programming, modular programming, object-oriented programming, etc.•To become a Master of SW design, one must study the designs of other masters–These designs contain patterns that must be understood, memorized, and applied repeatedly.•There are hundreds of these patternsRRRDesign Patterns•Design patterns represent solutions to problems that arise when developing software within a particular context–“Patterns == problem/solution pairs in a context”•Patterns capture the static and dynamic structure and collaboration among key participants in software designs–Especially good for describing how and why to resolve non-functional issues•Patterns facilitate reuse of successful software architectures and designs.RRRApplications•Wide variety of application domains:–drawing editors, banking, CAD, CAE, cellular network management, telecomm switches, program visualization•Wide variety of technical areas:–user interface, communications, persistent objects, O/S kernels, distributed systemsRRRCollaboration in the Observer Patternset_state()notify()update()get_state()update()get_state()ConcreteSubjectConcreteObserver1ConcreteObserver2RRRDesign Pattern Descriptions•Main Parts:–Name and Classification (see table in two more slides)–Intent: Problem and Context–Also known as (other well-known names)–Motivation: scenario illustrates a design problem–Applicability: situations where pattern can be applied–Structure: graphical representation of classes (class diagram, interaction diagram)–Participants: objects/classes and their responsibilities–Collaborations: how participants collaborate–Consequences: trade-offs and results–Implementation: pitfalls, hints, techniques for coding; language-specific issues–Sample Code–Known Uses: examples of pattern in real systems–Related Patterns: closely related; what are diffs.•Pattern descriptions are often independent of programming language or implementation detailsRRRDesign Pattern Space•Creational patterns:–Deal with initializing and configuring classes and objects•Structural patterns:–Deal with decoupling interface and implementation of classes and objects–Composition of classes or objects•Behavioral patterns:–Deal with dynamic interactions among societies of classes and objects–How they distribute responsibilityRRRCreational Structural BehavioralFactory MethodAbstract FactoryPrototypeSingletonBuilderAdapter (class)Adapter (object)BridgeFlyweightDecoratorProxyCompositeFacadeTemplate MethodChain of ResponsibilityCommandIteratorMediatorMementoObserverStateStrategyInterpreterVisitorCategorize Design Patterns PurposeClassObjectCompScopeRRRCategorization Terms•Scope: domain over which a pattern applies–Class Scope: relationships between base classes and their subclasses•Static semantics–Object Scope: relationships between peer objects•Some patterns apply to multiple scopes.RRRClass Scope•Class Creational: abstract how objects are instantiated –hide specifics of creation process–may want to delay specifying a class name explicitly when instantiating an object–just want a specific protocolRRRExample Class Scope•Use of Factory Method: instantiate members in base classes with objects created by subclasses.•Abstract Application class: create application-specific documents conforming to particular Document type•Application instantiates these Document objects by calling the factory method DoMakeDocument•Method is overridden in classes derived from Application•Subclass DrawApplication overrides DoMakeDocument to return a DrawDocument objectRRRClass Structural•Class Structural: use inheritance to compose protocols or code•Example: –Adapter Pattern: makes one interface (Adaptee’s) conform to another --> uniform abstraction of different interfaces.–Class Adapter inherits privately from an Adaptee class. –Adapter then expresses its interface in terms of the Adaptee’s.RRRClass Behavioral•Class Behavioral: capture how classes cooperate with their subclasses to satisfy semantics.–Template Method: defines algorithms step by step.–Each step can invoke an abstract method (that must be defined by the subclass) or a base method.–Subclass must implement specific behavior to provide required servicesRRRObject Scope•Object Patterns all apply various forms of non-recursive object composition.•Object Composition: most powerful form of reuse•Reuse of a collection of objects is better achieved through variations of their composition, rather than through
View Full Document