Recommendable # 971589162217 # philippine Young Call Girls in Dubai By Marina...
Design patterns
1. Design Patterns – Eran Toch
Methodologies in Information System Development
Design Patterns:Design Patterns:
Talking in the Design LanguageTalking in the Design Language
Eran Toch
Methodologies in the Development
of Information Systems
2. Design Patterns – Eran Toch
2November 2003
AgendaAgenda
• What is a Design Pattern?
• Structural Patterns
– The Composite Pattern
• Behavioral Patterns
– The Strategy Pattern
• Creational Patterns
– The Singleton Pattern
• Human Interaction Patterns
– Go Back to a Safe Place
• Summary
3. Design Patterns – Eran Toch
3November 2003
What is a Design Pattern?What is a Design Pattern?
In Short, a solution
for a typical problem
“a description of a recurrent
problem and of the core of possible
solutions.“
4. Design Patterns – Eran Toch
4November 2003
Why do we need them?Why do we need them?
• Problems are not always unique. Reusing
existing experience might be proved useful.
• We need a common language to describe
problems and solutions.
• The Design of Object-Oriented systems limits
the scope of problems and solutions we can
talk about
5. Design Patterns – Eran Toch
5November 2003
History of Design PatternsHistory of Design Patterns
Christopher Alexander
A Pattern Language: Towns, Buildings Construction 1970’
1995’
2000’
Architecture
Object Oriented
Software Design
Other Areas:
HCI, Organizational Behavior…
Gang of Four (GoF)
Design Patterns: Elements of
Reusable Object-Oriented Software
Many Authors
6. Design Patterns – Eran Toch
6November 2003
Structure of a design patternStructure of a design pattern
• Pattern Name and Classification
• Intent
– a Short statement about what the pattern does
• Motivation
– A scenario that illustrates where the pattern would be
useful
• Applicability
– Situations where the pattern can be used
7. Design Patterns – Eran Toch
7November 2003
Structure of a design pattern – cont’dStructure of a design pattern – cont’d
• Structure
– A graphical representation of the pattern
• Participants
– The classes and objects participating in the pattern
• Collaborations
– How to do the participants interact to carry out their
responsibilities?
• Consequences
– What are the pros and cons of using the pattern?
• Implementation
– Hints and techniques for implementing the pattern
8. Design Patterns – Eran Toch
8November 2003
Classification of patternsClassification of patterns
• Structural
– Composite*, Decorator, Façade, Adapter…
• Behavioral
– Strategy*, Command, Observer, Chain of
Responsibilities…
• Creational
– Singleton*, Abstract Factory, Factory Method…
• Other
– User interface Patterns
• Go Back to a Safe Place
9. Design Patterns – Eran Toch
9November 2003
AgendaAgenda
• What is a Design Pattern?
• Structural Patterns
• Behavioral Patterns
• Creational Patterns
• Human Interaction Patterns
• Summary
10. Design Patterns – Eran Toch
10November 2003
The Composite PatternThe Composite Pattern
• Intent:
– Compose objects into tree structures to represent
part-whole hierarchies.
– Composite lets clients treat individual objects and
compositions of objects uniformly. This is called
recursive composition.
11. Design Patterns – Eran Toch
11November 2003
MotivationMotivation
When Processing the hierarchal
collection, we need to query the
type of the object (composite or
primitive) and act differently
Diagram reference: Design
Patterns [Gof]
12. Design Patterns – Eran Toch
12November 2003
Composite: ApplicabilityComposite: Applicability
• Use the Composite pattern when:
– You want to represent part-whole hierarchies of
objects.
– You want clients to be able to ignore the
difference between compositions of objects and
individual objects. Clients will treat all objects in
the composite structure uniformly.
13. Design Patterns – Eran Toch
13November 2003
Composite: StructureComposite: Structure
• Define an abstract base class that specifies the
uniform behavior.
• Subclass the Primitive and Composite classes of the
Component class.
Diagram reference: Design
Patterns [Gof]
14. Design Patterns – Eran Toch
14November 2003
Composite: ConsequencesComposite: Consequences
• Benefits
– It makes it easy to add new kinds of components
– It makes clients simpler, since they do not have to
know if they are dealing with a leaf or a composite
component
• Liabilities
– It makes it harder to restrict the type of components of
a composite
15. Design Patterns – Eran Toch
15November 2003
Composite: Known UsesComposite: Known Uses
1. A GUI system has window objects which can
contain various GUI components (widgets) such as,
buttons and text areas. A window can also contain
widget container objects which can hold other
widgets.
Concrete examples: Java Swing, MFC
2. Folder based file system
3. Arithmetic expressions
16. Design Patterns – Eran Toch
16November 2003
AgendaAgenda
• What is a Design Pattern?
• Structural Patterns
• Behavioral Patterns
• Creational Patterns
• Human Interaction Patterns
• Summary
17. Design Patterns – Eran Toch
17November 2003
The Strategy PatternThe Strategy Pattern
• Intent:
– Define a family of algorithms, encapsulate each one,
and make them interchangeable.
– Strategy lets the algorithm vary independently from
clients that use it.
18. Design Patterns – Eran Toch
18November 2003
Strategy: MotivationStrategy: Motivation
The client wants to use the algorithm
without knowing which one to use in
advance. We want to add new
algorithms without changing the
client class.
19. Design Patterns – Eran Toch
19November 2003
Strategy: StructureStrategy: Structure
• Encapsulate the behavior of the context class in a
separate algorithm class.
• The context class keeps a reference to the algorithm
class and passes on the messages.
• The algorithm class can be sub-classed to support
multiple algorithms.
20. Design Patterns – Eran Toch
20November 2003
Strategy: ConsequencesStrategy: Consequences
• Benefits
– Provides an alternative to subclassing the Context
class to get a variety of algorithms or behaviors
– Keeps the client clean from large conditional
statements
– Provides a choice of implementations for the same
behavior
• Liabilities
– Increases the number of objects
– All algorithms must use the same Strategy interface
– We still need conditional statements!
21. Design Patterns – Eran Toch
21November 2003
Strategy: Known UsesStrategy: Known Uses
• QSIA Learning System
• Layout Manager in Java
Swing
• Sorting algorithms,
memory allocation
algorithms and more…
22. Design Patterns – Eran Toch
22November 2003
AgendaAgenda
• What is a Design Pattern?
• Structural Patterns
• Behavioral Patterns
• Creational Patterns
• Human Interaction Patterns
• Summary
23. Design Patterns – Eran Toch
23November 2003
The Singleton PatternThe Singleton Pattern
• Intent.
– Ensure a class only has one instance, and provide a
global point of access to it.
• Motivation.
– Sometimes, an application needs one, and only one,
instance of an object. For example, we want just one
window manager. Or just one factory for a family of
products.
– We need to have that one instance easily accessible.
– And we want to ensure that additional instances of the
class can not be created.
24. Design Patterns – Eran Toch
24November 2003
Singleton: StructureSingleton: Structure
• Declare the single instance as a private static data
member.
• Provide a public static member function that
encapsulates all initialization code, and provides
access to the instance.
25. Design Patterns – Eran Toch
25November 2003
Singleton: Example CodeSingleton: Example Code
public class Singleton {
// The private reference to the one and only instance.
private static Singleton uniqueInstance = null;
// An instance attribute.
private int data = 0;
/**
* Returns a reference to the single instance.
* Creates the instance if it does not yet exist.
*/
public static Singleton instance() {
if(uniqueInstance == null)
uniqueInstance = new Singleton();
return uniqueInstance;
}
/**
* The Singleton Constructor. Note that it is private!
* No client can instantiate a Singleton object!
*/
private Singleton() {}
}
26. Design Patterns – Eran Toch
26November 2003
Singleton: Example Code – cont’dSingleton: Example Code – cont’d
public class TestSingleton {
public static void main(String args[]) {
// Get a reference to the single instance of Singleton.
Singleton s = Singleton.instance();
// Set the data value.
s.setData(34);
System.out.println("First reference: " + s);
System.out.println("Singleton data value is: " + s.getData());
// Get another reference to the Singleton.
// Is it the same object?
s = null;
s = Singleton.instance();
System.out.println("nSecond reference: " + s);
System.out.println("Singleton data value is: " + s.getData());
}
}
What will be the output?
27. Design Patterns – Eran Toch
27November 2003
AgendaAgenda
• What is a Design Pattern?
• Structural Patterns
• Behavioral Patterns
• Creational Patterns
• Human Interaction Patterns
• Summary
28. Design Patterns – Eran Toch
28November 2003
Human Interaction PatternsHuman Interaction Patterns
• A Pattern language to describe human
interaction situations
• Examples:
– Go Back to a Safe Place
– Form
– Control Panel
– WYSIWYG Editor
– Hierarchical Set
– Map of Navigable Spaces
– More…
29. Design Patterns – Eran Toch
29November 2003
Go Back to a Safe PlaceGo Back to a Safe Place
• Problem:
– How can the artifact make navigation easy, convenient, and
psychologically safe for the user?
• Forces:
– A user may forget where they were, if they stop using the artifact
while they're in the middle of something and don't get back to it
for a while.
– If the user gets into a space or a state that they don't want to be
in, they will want to get out of it in a safe and predictable way.
– The user is more likely to explore an artifact if they are assured
that they can easily get out of an undesired state or space; that
assurance engenders a feeling of security.
30. Design Patterns – Eran Toch
30November 2003
Go Back to a Safe PlaceGo Back to a Safe Place
• Solution:
– Provide a way to go back to a checkpoint of the user's
choice.
• Examples:
– The "Home" button on a Web browser
– Turning back to the beginning of a chapter in a
physical book or magazine
– The “undo" feature on some computer applications
31. Design Patterns – Eran Toch
31November 2003
AgendaAgenda
• What is a Design Pattern?
• Structural Patterns
• Behavioral Patterns
• Creational Patterns
• Human Interaction Patterns
• Summary
32. Design Patterns – Eran Toch
32November 2003
SummarySummary
• Patterns learned:
– Composite, Strategy, Singleton, Go Back to a Safe
Place.
• Advantages of Design Patterns:
– They capture expertise and make it accessible to non-
experts.
– Their names collectively form a vocabulary that helps
developers communicate better.
– They help people understand a system more quickly
when it is documented with the patterns it uses.
33. Design Patterns – Eran Toch
33November 2003
ReferencesReferences
• Design Patterns: Elements of Reusable Object-Oriented
Software, Gamma E. et el., 1995, Addison-Wesley.
• A course from Bob Tarr from UMBC University
http://www.research.umbc.edu/~tarr/dp/fall00/cs491.html
• The Design Patterns Java Companion, James W. Cooper (an
online version of the book)
http://www.patterndepot.com/put/8/JavaPatterns.htm
• A Site dedicated to Design Patterns by Vince Huston
http://home.earthlink.net/~huston2/dp/patterns.html
• Seven Habits of Successful Pattern Writers, John Vlissides
http://hillside.net/patterns/papers/7habits.html
• COMMON GROUND: A Pattern Language for Human-
Computer Interface Design, Jenifer Tidwell,
http://www.mit.edu/~jtidwell/common_ground_onefile.html
34. Design Patterns – Eran Toch
34November 2003
Doesn’t it go too far?Doesn’t it go too far?
• Taken from Vince Huston’s site about Design
Patterns:
35. Design Patterns – Eran Toch
Methodologies in Information System Development
Thanks!Thanks!