Singleton is not_the_only_pattern

3,589 views

Published on

There are more patterns than just Singleton... and Singleton may not be such a great idea after all

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,589
On SlideShare
0
From Embeds
0
Number of Embeds
456
Actions
Shares
0
Downloads
27
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Singleton is not_the_only_pattern

  1. 1. Singleton is not the only pattern Seb RoseSoftware Architect – Requirements Management Rational IBM, Edinburgh
  2. 2. A typical CV
  3. 3. The Gang of Four● Patterns first popularised by Design Patterns Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides● Published 1995
  4. 4. More followed …
  5. 5. 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
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. 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? Dont. Your programs will thank you for taking the time to think about design instead.” – Kent Beck, 2003
  12. 12. An AlternativeYou have this system... ● You try globals... well, probably you dont: 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 its a bad thing and its obvious to you. ● So you try passing parameters: they overwhelm you. ● You refactor a bit (à la Fowler) and before you know it youve got ENCAPSULATED CONTEXT. ● You carry on down this path, you get more mileage here, but over time it starts to look like Footes BIG BALL OF MUD.The solution is to reduce the coupling, improve the cohesion, but how? Allan Kelly, 2005
  13. 13. Context Encapsulation Pattern Language“Context Encapsulation: Three Stories, a Language and Some Sequences” Kevlin Henney, 2006http://www.two-sdg.demon.co.uk/curbralan/papers/europlop/ContextEncapsulation.pdf

×