Upload
seb-rose
View
2.958
Download
2
Tags:
Embed Size (px)
DESCRIPTION
There are more patterns than just Singleton... and Singleton may not be such a great idea after all
Citation preview
Singleton is not the only patternSeb Rose
Software Architect – Requirements ManagementRational IBM, Edinburgh
A typical CV
The Gang of Four
● Patterns first popularised by Design PatternsErich Gamma, Richard Helm, Ralph Johnson, John Vlissides
● Published 1995
More followed …
Where did it all start?
● Christopher Alexander (1936 -)● Chemistry & Physics, Trinity, Cambridge,
1957● Ph.D. Architecture, Harvard (1st ever
awarded)● Professor Architecture, Berkley, 1963● “Notes on the synthesis of form”, 1964● First Gold Medal Research, American
Institute of Architects, 1972● “A Pattern Language”, 1977
Alexandrian Form
● Picture – archetypical example● Introductory paragraph - context● Headline (in bold) – essence of problem● Body – background, motivation, variations● Solution (in bold)● Diagram (of solution)● [Smaller] related patterns
The Hillside Group
● Promotes patterns in software community● Formed 1993 by Ward Cunningham,
Ralph Johnson, Ken Auer, Hal Hildebrand, Grady Booch, Kent Beck and Jim Coplien
● Cunningham invented Wiki to discuss patterns
● Sponsors PLoP conferences & books● Hillside Group: www.hillside.net● WikiWikiWeb: www.c2.com
Canonical [GoF] Form● Name● Alias(es) [Also known as]● Context [Applicability]● Problem [Intent]● Forces [Motivation]● Solution [Participants, Structure,
Collaborations, Implementation]● Example (optional) [Sample code]● Resulting context [Consequences]● Rationale (optional)● Known uses● Related patterns
Pattern Languages
● Structured method of describing good design practices within a field of expertise
● A network of patterns that call upon one another
● Help the designer move from problem to problem in a logical way
● Allow for many different paths through the design process
Pattern Sequences
● Pattern languages are played out as sequences
● Sequences show paths through a language
● Commonly illustrated through stories● Give rise to common design fragments● Can be shown diagrammatically, or as a
list
And so, back to Singleton● “Ensure a class has only one instance, and
provide a global point of access to it.” – GoF, 1995
● “[Singleton] invariably causes problems with coupling and execution, and is more than a little overused” – Henney, 2005
● “How do you provide global variables in languages without global variables? Don't. Your programs will thank you for taking the time to think about design instead.” – Kent Beck, 2003
An AlternativeYou have this system...
● You try globals... well, probably you don't: the one thing you learned in school was no globals.
● You try for SINGLETON, it is in the book, it is good... but then you find you have these nasty ripples... then someone tells you it's a bad thing and it's obvious to you.
● So you try passing parameters: they overwhelm you.● You refactor a bit (à la Fowler) and before you know it you've got
ENCAPSULATED CONTEXT.● You carry on down this path, you get more mileage here, but over
time it starts to look like Foote's BIG BALL OF MUD.The solution is to reduce the coupling, improve the cohesion, but how?
Allan Kelly, 2005
Context Encapsulation Pattern Language
http://www.two-sdg.demon.co.uk/curbralan/papers/europlop/ContextEncapsulation.pdf
“Context Encapsulation: Three Stories, a Language and Some Sequences”Kevlin Henney, 2006