DesignPattenl

DesignPattenl - cs2340:DesignPatterns Fall 2008...

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

View Full Document Right Arrow Icon
Smalltalk Design Patterns 1 cs2340:Design Patterns Fall 2008
Background image of page 1

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

View Full DocumentRight Arrow Icon
Smalltalk Design Patterns 2 Design Expertise Architectural Styles Frameworks Design Patterns Language Idioms
Background image of page 2
Smalltalk Design Patterns 3 What are design patterns? Proven solutions to common problems Capture design expertise Aid in meeting quality factors
Background image of page 3

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

View Full DocumentRight Arrow Icon
Smalltalk Design Patterns 4 Information Expert Assign a responsibility to the class that has the information necessary to fulfill the responsibility. Sales Date Time Contains LineItem quantity ProductSpec DescribedBy 1 1..* * 1 Description Price itemID Start assigning responsibilities by clearly stating the responsibility. Who should be responsible for knowing the grand total of a sale? Who should be responsible for saving the Sale in the database?
Background image of page 4
Smalltalk Design Patterns 5 Singleton Problem: I want to limit the application to only one instance of a particular class, but need global access to that class. Normally used to control access to key resources. Solution? override new, make static accessor method.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Smalltalk Design Patterns 6 Singleton Singleton +instance: Singleton +new - instance:Singleton new "override to get the instance" ^Singleton instance instance instance ifNil:[ instance := self basicNew initialize. ]. ^ instance See Boolean, True, False classes
Background image of page 6
Smalltalk Design Patterns 7 Singleton Problems Garbage Collection Use Object Preserver class Anyone can get reference to class See “Why Singletons are Evil” Subclassing Watch out for default public constructors Introduces coupling, reduces reuse
Background image of page 7

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

View Full DocumentRight Arrow Icon
Smalltalk Design Patterns 8 Factory Define an interface for creating an object, but let subclasses decide which class to instantiate. Allows a class to defer instantiation to subclasses. Think of a multi-document application framework. An application object may know when an object needs to be created, but not which object. How do we create the correct object when needed? Can also be used when a complex initialization of objects
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 33

DesignPattenl - cs2340:DesignPatterns Fall 2008...

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

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