DOC PREVIEW
MSU CSE 870 - Lecture 27: OO Design Patterns

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Goals of Lecture Cover OO Design Patterns Lecture 27 OO Design Patterns Background Examples Kenneth M Anderson Object Oriented Analysis and Design CSCI 6448 Spring Semester 2001 April 24 2001 Pattern Resources Addison Wesley book published in 1995 Technical conference on Patterns The Portland Pattern Repository http c2 com ppr Patterns Homepage Erich Gamma Richard Helm Ralph Johnson John Vlissides Known as The Gang of Four Presents 23 Design Patterns ISBN 0 201 63361 2 http hillside net patterns patterns html Kenneth M Anderson 2001 2 Design Patterns Pattern Languages of Programming April 24 2001 Kenneth M Anderson 2001 3 April 24 2001 Kenneth M Anderson 2001 4 What are Patterns Patterns continued Christopher Alexander talking about buildings and towns Patterns can have different levels of abstraction In Design Patterns the book 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 Alexander et al A Pattern Language Oxford University Press 1977 April 24 2001 Kenneth M Anderson 2001 Patterns are not classes Patterns are not frameworks Instead Patterns are descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context 5 April 24 2001 Kenneth M Anderson 2001 6 Elements of a Pattern Patterns continued Pattern Name So patterns are formalized solutions to design problems More than just a handle for referring to the pattern Each name adds to a designer s vocabulary They describe techniques for maximizing flexibility extensibility abstraction etc Enables the discussion of design at a higher abstraction The Problem Gives a detailed description of the problem addressed by the pattern Describes when to apply a pattern These solutions can typically be translated to code in a straightforward manner Often with a list of preconditions April 24 2001 Kenneth M Anderson 2001 7 April 24 2001 Kenneth M Anderson 2001 8 Elements of a Pattern continued Elements of a Pattern continued The Solution The consequences Describes the elements that make up the design their relationships responsibilities and collaborations Does not describe a concrete solution Describes the results and tradeoffs of applying the pattern Critical for evaluating design alternatives Typically include Instead a template to be applied in many situations April 24 2001 Kenneth M Anderson 2001 Impact on flexibility extensibility or portability Space and Time tradeoffs Language and Implementation issues 9 April 24 2001 Design Pattern Template Pattern Name and Classification Creational Structural Behavioral Intent Also Known As Motivation Applicability April 24 2001 10 Examples Structure Participants Collaborations Consequences Implementation Sample Code Known Uses Related Patterns Kenneth M Anderson 2001 Kenneth M Anderson 2001 11 Singleton Factory Method Adapter Decorator Command State April 24 2001 Kenneth M Anderson 2001 12 Singleton Singleton continued Intent Applicability Ensure a class has only one instance and provide a global point of access to it Use the Singleton pattern when there must be exactly one instance of a class and it must be accessible to clients from a well known access point when the sole instance should be extensible by subclassing and clients should be able to use an extended instance without modifying their code Motivation Some classes represent objects where multiple instances do not make sense or can lead to a security risk e g Java security managers April 24 2001 Kenneth M Anderson 2001 13 April 24 2001 Singleton continued Kenneth M Anderson 2001 14 Singleton Structure Participants Just the Singleton class Collaborations Singleton Clients access a Singleton instance solely through Singleton s Instance operation static Instance public SingletonOperation public GetSingletonData Consequences Controlled access to sole instance Reduced name space versus global variables Permits a variable number of instances if desired April 24 2001 Kenneth M Anderson 2001 return uniqueInstance private static uniqueInstance private singletonData 15 April 24 2001 Kenneth M Anderson 2001 16 Factory Method Factory Method continued Intent Applicability Define an interface for creating an object but let subclasses decide which class to instantiate Use the Factory Method pattern when a class can t anticipate the class of objects it must create a class wants its subclasses to specify the objects it creates classes delegate responsibility to one of several helper subclasses and you want to localize the knowledge of which helper subclass is the delegate Also Known As Virtual Constructor Motivation Frameworks define abstract classes but any particular domain needs to use specific subclasses how can the framework create these subclasses April 24 2001 Kenneth M Anderson 2001 17 Factory Method continued April 24 2001 Kenneth M Anderson 2001 18 Factory Method Structure product FactoryMethod Participants Creator Product Product FactoryMethod AnOperation Defines the interface of objects the factory method creates Concrete Product Implements the Product Interface ConcreteProduct Creator declares the Factory method which returns an object of type Product instantiate ConcreteCreator FactoryMethod Concrete Creator overrides the factory method to return an instance of a Concrete Product return new ConcreteProduct April 24 2001 Kenneth M Anderson 2001 19 April 24 2001 Kenneth M Anderson 2001 20 Factory Method Consequences Adapter Factory methods eliminate the need to bind application specific classes into your code Potential disadvantage is that clients must use subclassing in order to create a particular ConcreteProduct Intent Convert the interface of a class into another interface clients expect Adapter lets classes work together that could not otherwise because of incompatible interfaces Also Known As Wrapper In single inherited systems this constrains your partitioning choices Motivation Sometimes a toolkit class that is designed for reuse is not reusable because its interface does not match the domain specific interface an application requires Provides hooks for subclasses Connects parallel class hierarchies Page 139 140 of Design Patterns provides an example April 24 2001 Kenneth M Anderson 2001 21 April 24 2001 Adapter continued Kenneth M Anderson 2001 22 Adapter continued Participants


View Full Document

MSU CSE 870 - Lecture 27: OO Design Patterns

Documents in this Course
HW2

HW2

3 pages

splc1

splc1

21 pages

Lessons

Lessons

3 pages

revision

revision

13 pages

ft1

ft1

12 pages

john.dsn

john.dsn

21 pages

Survey

Survey

2 pages

revision

revision

38 pages

Load more
Download Lecture 27: OO Design Patterns
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 27: OO Design Patterns and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 27: OO Design Patterns 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?