Colleen Crangle
• Woman in tech throughout the 70s and 80s• PhD in Philosophy (Logic and the Philosophy of
Language and Science), in follow-up to a BSc cum laude and an MSc in Computer Science and Mathematics from South Africa• Affiliated scholar with the Centre for the Study
of Language and Information at Stanford University and a partner in a small R&D business in Silicon Valley, California
Introduction to Design Patterns
Jackie Pollock
• Technical Consultant @ Kainos Software
• Joined June 2006 as Graduate Software Engineer
• Specialities:
• Document Management
• Workflow
• Scanning
• Integration
Who am I?
• What are design patterns?
• Why are they useful
• Types of design pattern
• Creational
• Structural
• Behavioural
Overview
• General repeatable solution to commonly occurring problem
• Not a finished design to be transformed directly into code
• Relationships and interactions between classes or objects without implementation specifics
What is a design pattern?
• Architectural concept by Christopher Alexander in 1977
• Ward Cunningham and Kent Beck 1987 “Using pattern languages for object-orientated programmers”
• 1990s Gamma, Helm, Johnson, and Vlissides. AKA: Gang of Four (GoF) book “Design Patterns: Elements of Reusable Object-Oriented Software”
Where did they come from?
• Design reuse
• Uniform design vocabulary
• Enhance understanding, restructuring, & team communication
• Basis for automation
• Transcends language-centric biases
• Abstracts away from many unimportant details
Benefits
• Require significant tedious & error-prone human effort to handcraft pattern implementations / design reuse
• Can be deceptively simple
• May limit design options
• Leaves some important details unresolved
Drawbacks
Creational Patterns
Factory
Creating objects without having to specify the exact class of object that will be created – will be determined at runtime
Abstract Factory
Creates family of objects at runtime – each of which will likely be a Factory in its own right
Separates construction of the various elements from the representation of the whole therefore same process can create different variants of theme
Builder
Only one instance of object across application. Used to provide single point of access. Should not be used to replace global variables
Singleton
Create complex objects by cloning existing ones and changing required characteristics. Useful when cost of new objects is prohibitive
Prototype
Structural Patterns
Converts an existing interface into another that your application can use.
Adapter
Treat a group of objects the same way as a single instance of object. Tree structures with a has-a relationship
Composite
Add behaviour to object without affecting behaviour of other objects from the same class
Decorator
Simplified interface to larger body of code. Reduces dependencies on inner class objects, wraps complex product APIs in manageable layer
Facade
Placeholder for another object, controlling access. Used for lazy loading resource hungry objects
Proxy
Behavioural Patterns
Turns requests into objects, separating out the code making the request from the object performing it
Command
Access elements of collection sequentially without focusing on underlying object types
Iterator
When one object changes state, all dependent objects notified and updated. View element of Model-View-Controller pattern
Observer
Object alters behaviour when internal state changes
State
Word of Caution
Always go for simplistic approach rather than applying patterns to every situation
If you force-fit a pattern into a situation where the pattern doesn’t apply, you are, by definition, not following the pattern
• Books
• Design Patterns
• Head First Design Patterns
• Design Patterns for Dummies
• Online
• Slideshare
• Pluralsight
• SourceMaking
• Wikipedia
• Image Credits
• Nelleke Verhoeff (Yepr)
Resources
Finish
• Any queries?• [email protected]
• Twitter• #WomenWhoCodeBelfast• @WWCBelfast, @nirushika
Looking forward to seeing you at our next event!