14 - design patterns

14 - design patterns - Design Patterns Design patterns were...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Design Patterns Design patterns were developed by the architect Christopher Alexander in the 1970’s to describe elements of architectural design. 1 His ideas were picked up by the object-oriented programming community in the mid 1990’s and applied to software design problems. 2 You can think of design patterns as a language about solving problems in system design without committing to any particular programming language: First study the possible system architectures, then decide on a suitable implementation language. This is important; you want the architecture and problem structure to drive your implementation NOT the programming language. Patterns fall into categories including: Creational Behavioral Structural Etc. Some examples of patterns follow. 3 1 A Pattern Language , C. Alexander, Oxford University Press, 1977. 2 Design Patterns , Erich Gamma et al , Addison-Wesley, 1995. 3 Based on patterns published at http://www.patterndigest.com
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Name: Singleton Category : Creational Intent Ensure a class has only one instance and provide a global point of access. Solution: 1. Declare the constructor(s) as Protected; 2. Declare a static "self" pointer to hold a reference to the single instance when it is created; 3. Declare a static "instance" function which creates and returns the single instance if the self pointer is NULL, otherwise it just returns the previously created instance. 4. Declare a protected destructor that sets the "self" pointer to NULL 5. Declare other methods and attributes as needed normally. 6. Clients access the singleton by calling the static instance function to get a reference to the single instance and then using it to call other methods. 7. Clients must not store this instance reference -- Each code segment that needs to access the singleton should call the instance function, perform the work needed and then discard the reference as quickly as possible. Consequences
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

14 - design patterns - Design Patterns Design patterns were...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online