design_patterns_III - Review: Design Pattern Structure A...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name So when someone says “Adapter” you know what they mean So you can communicate design ideas as a “vocabulary” A design pattern describes the core of a solution to a recurring design problem So you don’t have to reinvent known design techniques So you can benefit from others’ (and your) prior experience A design pattern is capable of generating many distinct design decisions in different circumstances So you can apply the pattern repeatedly as appropriate So you can work through different design problems using it
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 332: Design Patterns Three More Design Patterns Singleton (creational) Provides access to a single (or indexed) instance Prototype (creational) Polymorphic duplication of heterogeneous types Visitor (behavioral) Allows interaction with heterogeneous collections Compile time dispatching is standard, but can emulate with dynamic type casting or RTTI
Background image of page 2
CSE 332: Design Patterns Creational Patterns Help define how objects are created/initialized May emphasize class or interaction diagrams Examples Factory Method Singleton Prototype
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 332: Design Patterns Single Global Instance Challenges Only one object of a type is needed or allowed in a program Whether or not the object is needed at all may vary Need to make sure the object is initialized before first use Motivates use of the Singleton pattern Instantiates the object on-demand (if requested) If no request is made, the object is never created (efficient) Makes it easy to obtain an alias from anywhere in program Don’t need to pass a reference/pointer up and down the call stack Initializes object before first alias to it is handed out Lifetime of the object covers interval of its possible use
Background image of page 4
CSE 332: Design Patterns Singleton Pattern Problem Want to ensure a single instance of a class, that’s shared by all uses throughout a program (e.g., the Portfolio, the Zoo ) Context Need to address ordering of initialization versus usage E.g., usage from different source files than where the object is defined Solution core Static pointer member variable is initialized to 0 (before main starts)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/19/2011 for the course CSE 332S taught by Professor Smart during the Spring '08 term at Washington University in St. Louis.

Page1 / 14

design_patterns_III - Review: Design Pattern Structure A...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online