Download presentation
Presentation is loading. Please wait.
Published byHerbert Ford Modified over 9 years ago
1
D ESIGN P ATTERNS Breno Batista Machado Weslei A. de T. Marinho
2
T ALK O UTLINE Pattern Definition GoF Patterns GoF Patterns Classification Creational Patterns Structural Patterns Behavioral Patterns Architectural Patterns Idioms
3
W HAT IS A P ATTERN ? "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice“ (Christopher Alexander)
4
W HAT IS A P ATTERN ? “Pattern is a named and well-known problem/solution pair that can be applied in new contexts, with advice on how to apply it in novel situations and discussion of its trade-offs, implementations, variations, and so forth.” (Craig Larman)
5
W HY USE P ATTERNS ? A pattern addresses a recurring design problem that arises in specific design situations, and presents a solution to it. Patterns document existing, well-proven design experience. Patterns identify and specify abstractions that are above the level of single classes and instances, or of components. Patterns provide a common vocabulary and understanding for design principles Patterns are a means of documenting software architectures.
6
T YPES OF P ATTERNS Architectural Patterns Design Patterns Idioms … E.g.: Usability Patterns Anti-Patterns
7
B ASIC P ATTERN M ETAMODEL Problem Solution Consequence Pattern name *
8
T HE S ACRED E LEMENTS OF THE F AITH FM Factory Method 107 PT Prototype 117 AF Abstract Factory 87 BU Builder 97 S Singleton 127 The role origins (Creational) CP Composite 163 PX Proxy 207 A Adapter 139 D Decorator 175 FA Facade 185 BR Bridge 151 The role structure FL Flyweight 195 CR Chain of Responsibility 223 TM Template Method 325 SR Strategy 315 CD Command 233 MM Memento 283 MD Mediator 273 ST State 305 O Observer 293 IT Iterator 257 IN Interpreter 243 V Visitor 331 The role behaviors
9
G O F P ATTERNS C LASSIFICATION Table 1: Design pattern space Purpose CreationalStructuralBehavioral Scope Class Factory MethodAdapterInterpreter Template Method Object Abstract FactoryAdapterChain of Responsibility BuilderBridgeCommand PrototypeCompositeIterator SingletonDecoratorMediator FacadeMemento ProxyFlyweight Observer State Strategy Visitor
10
A BSTRACT F ACTORY Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Also Knows As: Kit
11
A BSTRACT F ACTORY - M OTIVATION
12
A BSTRACT F ACTORY - S TRUCTURE
13
S IGLETON Intent: Ensure a class only has one instance, and provide a global point of access to it.
14
S INGLETON
15
A DAPTER
20
F ACADE Intent: Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
21
F ACADE
26
T EMPLATE M ETHOD Intent: Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine steps of an algorithm changing the algorithm’s structure.
27
T EMPLATE M ETHOD Motivation: Think about to prepare coffee and tea.
28
T EMPLATE M ETHOD Structure
29
T EMPLATE M ETHOD Structure
30
T EMPLATE M ETHOD Consequences: Template Method prove code reuse It lead to an inverted control structure: “the Hollywood principle” that says “Don’t call us, we’ll call you.”
31
O BSERVER Intent: Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Also Know As: Dependents, Publish-Subscribe Motivation: Maintain a consistency between objects in a system that is partitioned into a collection of cooperating classes.
32
O BSERVER
34
Consequences: Support for broadcast communication Unexpected updates
35
A RCHITECTURAL P ATTERNS It expresses a fundamental structural organization schema for software systems. It provides a set of predefined subsystems, specifies their responsibilities, and includes rules and guidelines for organizing the relationships between them.
36
A RCHITECTURAL P ATTERNS We’ll see… Layers Model View Controller
37
L AYERS It helps to structure applications that can be decomposed into groups of subtasks in which each group of subtasks is at a particular level of abstraction. Example: Networking Protocols. Context: A large system that requires decomposition.
38
L AYERS Structure Individual Layer Layers collaborating
39
L AYERS Consequences: Reuse of layers Support for standardization Dependencies are kept local Exchangeability Cascades of changing behavior Lower efficiency Difficulty of establishing the correct granularity of layers
40
M ODEL -V IEW -C ONTROLLER It divides an interactive application into three components. The model contains the core functionality and data. Views display information to the user. Controllers handle user input. Example: A system for political elections with many representations. Context: Interactive applications with a flexible human-computer interface
41
M ODEL -V IEW -C ONTROLLER Structure
42
M ODEL -V IEW -C ONTROLLER Structure
43
M ODEL -V IEW -C ONTROLLER Consequences: Multiple views of the same model Synchronized views “Plugglable” views and controllers Increased complexity Potential for excessive number of updates Intimate connection between view and controller Close coupling of views and controller to a model
44
I DIOMS Idioms are low-level patterns specific to a programming language. An idiom describes how to implement particular aspects of components or the relationships between them with the features of the giver language. Idioms provides a help to solve some recurring problem with a programming language. Ex. Memory management, object creation, naming of methods, source cod formatting and so on.
45
B IBLIOGRAPHY Freeman, E., Sierra, K., Bates, B. 2004. Head First Design Patterns. O’Reilly Media, Inc. Gamma, E., Helm, R., Johnson, R., Vlissides, J. 1995. Design Patterns Elements of Reusable Object-Oriented Software. Addison-Wesley Pub Co. Larman, C. 2004. Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, Third Edition. Pearson Education, Inc. Schmidt, D., Stal, M., Rohnert, H., Buschmann, F. 1996. PATTERN-ORIENTED SOFTWARE ARCHITECTURE VOLUME 1: A System of Patterns. John Wiley & Sons Ltd.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.