CS616: Software Engineering
Spring 2009
Design Patterns
Sami Taha
Content
• Introduction
• Classification of patterns– List of patterns
• GoF Patterns Template
• Case Study: Observer pattern
Introduction
• Design reuse
• Design Patterns motivation
Classification of patterns
• Creational patterns the process of object creation – Singleton
• Single instance
– Factory Method– Building– Prototype
Structural patterns
deal with the composition of classes or objects
• Façade– Unified interface
• Proxy– Protection– Synchronization– Count references– Cache
• Bridge• Composite
Behavioral patternsThe ways classes or objects interact and distribute responsibility
• Observer • Visitor• State • Command • Strategy• Chain of Responsibility • Interpreter• Integrator• Mediator• Memento • Template Method
GoF Patterns Template
• Pattern Name and classification• Intent
– What the pattern does• Motivation
– Scenario where the pattern would be useful• Applicability
– Situations to apply the design pattern• Structure
– Graphical representation• Participants
– Classes/object participating and responsibilities
GoF Patterns Template cont.
• Collaborations– How the participants collaborates
• Consequences– Pros and consequences
• Implementation– Pitfalls, hints, or techniques should you be aware of
• Sample Code and Usage– Code fragment
• Known uses– Examples in real systems
Case Study
• Observer Pattern– Pattern classification
• Behavioral pattern
– Motivation– Applicability
• When a change to one object requires changing others
• When an object should be able to notify other objects
Case Study cont..
– Structure
Case Study cont..
– Known usesThe observer pattern is implemented in many
programming libraries specially GUI toolkits
Examples
Java Swing
Boost.Signals
QT
Signal/Slot Library
.Net remoting
The standard PHP library
References
• Wikipedia
• http://www.cs.mum.edu/