CSC/ECE 517 Fall 2012/ch2a 2w18 as: Difference between revisions
m (Builder definition + ref links added) |
m (Changed Heading) |
||
Line 9: | Line 9: | ||
__TOC__ | __TOC__ | ||
= | =Creational Patterns= | ||
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities <ref>Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf</ref>: | Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities <ref>Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf</ref>: | ||
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code. | * Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code. |
Revision as of 22:07, 20 October 2012
Abstract Factory and Builder Patterns
"Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice" - Christopher Alexander
"In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design".
A Design Pattern is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in Object - Oriented Languages help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.
Creational Patterns
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities <ref>Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf</ref>:
- Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.
- Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.
- Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.
Abstract Factory
- --Description--
- --Java Example--
- --Ruby Example--
Builder
The Builder Pattern is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects<ref>http://en.wikipedia.org/wiki/Builder_pattern</ref>.
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations<ref>http://www.oodesign.com/builder-pattern.html</ref>. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.
- --Java Example--
- --Ruby Example--
Comparison
References
<references />