Lab 11 (Creational Design Pattern (GoF) )
Lab 11 (Creational Design Pattern (GoF) )
Design Pattern:
Design patterns are evolved as reusable solutions to the problems that we encounter everyday of
programming.
“A pattern describes a problem that occurs often, along with a tried solution to the problem”
- Christopher Alexander, 1977
Design patterns are descriptions of communicating objects and classes that are customized to
solve a general design problem in a particular context.
A design pattern is not a finished design that can be transformed directly into code. It is a
description or template for how to solve a problem that can be used in many different situations.
1. Creational patterns
– Creating a collection of objects in flexible ways
2. Structural patterns
– Representing a collection of related objects
3. Behavioral patterns
– Capturing behavior among a collection of objects.
• In software engineering, creational design patterns are design patterns that deal with
object creation mechanisms, trying to create objects in a manner suitable to the
situation.
• The basic form of object creation could result in design problems or added complexity
to the design. Creational design patterns solve this problem by somehow controlling this
object creation
Design Purpose
Create individual objects in situations where the constructor alone is
inadequate.
Example:
Class Diagram:
Code:
Lab Task:
Design Purpose
Ensure a class (e.g S) has only one instance, and provide a global point of access to it.
Design Pattern Summary
Make the constructor of S private; define a private static attribute for Singleton class of type S;
define a public access or for it.