13
Singleton is not the only pattern Seb Rose Software Architect – Requirements Management Rational IBM, Edinburgh

Singleton is not_the_only_pattern

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Singleton is not_the_only_pattern

Singleton is not the only patternSeb Rose

Software Architect – Requirements ManagementRational IBM, Edinburgh

Page 2: Singleton is not_the_only_pattern

A typical CV

Page 3: Singleton is not_the_only_pattern

The Gang of Four

● Patterns first popularised by Design PatternsErich Gamma, Richard Helm, Ralph Johnson, John Vlissides

● Published 1995

Page 4: Singleton is not_the_only_pattern

More followed …

Page 5: Singleton is not_the_only_pattern

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

Page 6: Singleton is not_the_only_pattern

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

Page 7: Singleton is not_the_only_pattern

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

Page 8: Singleton is not_the_only_pattern

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

Page 9: Singleton is not_the_only_pattern

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

Page 10: Singleton is not_the_only_pattern

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

Page 11: Singleton is not_the_only_pattern

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

Page 12: Singleton is not_the_only_pattern

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

Page 13: Singleton is not_the_only_pattern

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