Lesson 1 Introduction ObjectOriented Behaviora l Paradigm Shift
Lesson 1: Introduction Object-Oriented Behaviora l Paradigm Shift, Inc. Software Factory Creational Design Structural PS 95&96 -MEF-L 1 -1 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Patterns Dr. M. E. Fayad Introduction - Page L 1 -1
Lesson Objectives o Be able to use patterns to define good design o Understand why design patterns are important o Discuss the process of discovering design patterns o Present other common techniques for reuse o Learn the answers of the following questions: ï What is a pattern? ï Where can we look to understand more about patterns? ï What are some examples of what might be considered patterns? and how can we catalog them? ï What is the process of discovering patterns? ï What is the potential impact of patterns? PS 95&96 -MEF-L 1 -2 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -2
Introduction • Object-oriented design patterns and frameworks help to improve key software quality factors – e. g. , reuse, extensibility, modularity, performance • OO design patterns support reuse of software architecture – Design patterns capture the static and dynamic structures and collaborations of successful solutions to problems that arise when building applications in a particular domain. • Frameworks support reuse of design and code – A framework is a set of cooperating classes that make up a reusable design for a specific domain PS 95&96 -MEF-L 1 -3 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -3
Design Patterns: Properties & Definitions • [Webster] A pattern is a fully realized form, original, or model accepted, or proposed for imitation. • [Webster] A pattern is something regarded as normative example to be copied; archetype ; exemplar. • [Alexander 79] A pattern is a solution to a problem in a context. • [Alexander 79] A pattern has three parts: – Problem(s) – Context – Solution • A pattern offers a workable solutions. • Patterns are rules of thumbs that can be used again and again -- useful, practical “how-to” guideline. PS 95&96 -MEF-L 1 -4 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -4
Design Patterns: More Properties & Definitions • [Gamma 95. ] Design patterns identify, name, and describe common and recurring designs appearing frequently in object-oriented systems. • [Gamma 95] You can think of a design pattern as a micro architecture that contributes to overall system architecture. • Each design pattern tends to be relatively small in size and scope. • [Coplien 92] Patterns are a way of describing, documenting, and creating system architectures for software. • Patterns tend not to be domain specific. • Patterns are one of the primary mechanisms that people use for passing on expertise to others. PS 95&96 -MEF-L 1 -5 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -5
Patterns of Learning • Solutions to most challenging areas of human endeavor are deeply rooted in patterns – An important goal of education and training is to transmit patterns from generation to generation. • We will use the analogy of learning to play chess to explore the use of design patterns • In many ways, learning to develop good software is similar to learning to play good chess – Though the consequences of failure are often less dramatic PS 95&96 -MEF-L 1 -6 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -6
Becoming a Chess Master • First learn rules and physical requirements – e. g. , names of the 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 thread, etc. • Study the games of other masters – These games contain patterns that must be understood, memorized, and applied repeatedly • There are thousands upon thousands of these patterns PS 95&96 -MEF-L 1 -7 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -7
Becoming a Master Software Designer • First learn rules and physical requirements – e. g. , the algorithms, data structures, software methods and techniques, analysis guidelines , etc. • Then learn principles of software engineering – e. g. , modularity, information-hiding, OO analysis, design, and programming, etc. • Study the designs of other masters – These designs contain patterns that must be understood, memorized, and applied repeatedly • There are thousands upon thousands of these patterns PS 95&96 -MEF-L 1 -8 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -8
Design Patterns • Design Patterns represent solutions to problems that arise when developing software within a particular context – Patterns == problem/solution pairs in a context • Design Patterns capture the static and dynamic structure and collaboration among key participants in software designs – Design patterns are particularly useful for articulating how and why to solve non-functional forces • Design Patterns facilitate reuse of successful software architecture and design PS 95&96 -MEF-L 1 -9 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -9
A Design Pattern Has Four Essential Elements (1) Abstract Factory Pattern’s Name: Design Problem: ðPattern’s Name – A handle – Part of Design Vocabulary Solution: Consequences: – Makes it easier to think about design and to communicate them and their trade-offs to others – Finding good names is hard Design Pattern’s Description Form ðDesign Problem – Describes when to apply the pattern – Explains the problem and its context – Might describe a class or object structures that are symptomatic of an inflexible design – Might describe assumptions or a list of conditions before applying the pattern PS 95&96 -MEF-L 1 -10 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -10
A Design Pattern Has Four Essential Elements (2) Abstract Factory Pattern’s Name: Design Problem: Solution: Consequences: Design Pattern’s Description Form ðSolution – Describes the elements that make up the design, their relationships, responsibilities, and collaborations – Doesn’t describe a particular concrete design because a pattern is like a template that can be applied in many different situations ðConsequences – The result and trade-offs of applying the pattern. – Critical for evaluating design alternatives and understanding the cost and the benefits of applying the pattern – Includes the pattern’s impact on a system’s flexibility, extensibility, or portability. Design pattern descriptions are often independent of programming languages or implementation details PS 95&96 -MEF-L 1 -11 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -11
Design Pattern Space ðCreational Patterns Design Patterns Catalog µ Deal with initializing and configuring classes and objects ðStructural Patterns µ Deal with decoupling interface and implementation of classes and objects ðBehavioral Patterns µ Deal with dynamic interactions among societies of classes and objects PS 95&96 -MEF-L 1 -12 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -12
Samples of Creational Patterns ð Abstract Factory Design Patterns Catalog µ Factory for building related objects ð Builder µ Factory for building complex objects incrementally ð Factory Method µ Method in a derived class creates associates ð Prototype µ Factory for cloning new instances from a prototype ð Singleton µ Factory for a singular (Sole) instance PS 95&96 -MEF-L 1 -13 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -13
Samples of Structural Patterns ð Adapter Design Patterns Catalog µ Translator adapts a server interface for a client ð Bridge µ Abstraction for binding one of many implementations ð Composite µ Structure for building recursive aggregations ð Decorator µ Decorator extends an object transparently ð Flyweight µ Many fine-grained objects shared efficiently PS 95&96 -MEF-L 1 -14 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -14
Samples of Behavioral Patterns (1) ð Chain of Responsibility Design Patterns Catalog µ Request delegated to the responsible service provider ð Command µ Request as First-Class object ð Mediator µ Mediator coordinates interactions between its associates ð Memento µ Snapshot captures and restores object states privately PS 95&96 -MEF-L 1 -15 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -15
Samples of Behavioral Patterns (2) ð Interpreter µ Language interpreter for a small grammar Design Patterns Catalog ð Iterator µ Aggregate elements are accessed sequentially ð Strategy µ Abstraction for selecting one of any algorithms ð Observer µ Dependents update automatically when a subject changes ð State µ Object whose behavior depends on its state PS 95&96 -MEF-L 1 -16 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -16
The Process of Discovering Patterns ðExperience ðDo it yourself µ Building things and watch yourself as you build them ðWatch others doing it µ Watch others performing or building things. This is called Protocol Analysis ðCatalog what you have done ðTeach and learn PS 95&96 -MEF-L 1 -17 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -17
The Potential impact of Patterns HUGE PS 95&96 -MEF-L 1 -18 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -18
Why? Patterns provide: ðA basis for architectural consistency ðA higher-level (design) approach for software problems ðA higher-level style convention ðA teaching vehicle Design Patterns Make Some of the Chaotic Problems Simple. PS 95&96 -MEF-L 1 -19 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -19
Why are Design Patterns Important? Œ Achieving Software Design Reuse A reusable Base of Experience Ž A Documentation and Learning Aid A Target for Refactoring An Adjunct to Existing Methodologies ‘ Architectural Elements ’ Delegation and Double Dispatch “ Enhancing Communication ” Enhancing Maintainability PS 95&96 -MEF-L 1 -20 Copyright © 1995 -2004 Active Frameworks, Inc. . - All Rights Reserved - V 2. 0 Dr. M. E. Fayad Introduction - Page L 1 -20
- Slides: 20