01-01 Creational Patterns

来源:互联网 发布:ubuntu win10启动项 编辑:程序博客网 时间:2024/05/01 13:54

Overview

When will use it
Creational patterns prescribe the way that objects are created. These patterns are used when a decision must be made at the time a class is instantiated. Typically, the details of the classes that are instantiated – what exactly they are, how, and when they are created – are encapsulated by an abstract superclass and hidden from the client class, which knows only about the abstract class or the interface it implements. The specific type of the concrete class is typically unknown to the client class

What Design Pattern Does it Include

Factory Method

Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Varying: subclass of object that is instantiated.

Abstract Factory

Provide an interface for creating families of related or dependent objects without specifying their concrete classes.Varying: families of product objects.

Builder

Separate the construction of a complex object from its representation so that the same construction process can create different representations.
Varying: how a composite object gets created.

Prototype

Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
Varying: class of object that is instantiated.

Singleton

Ensure a class only has one instance, and provide a global point of access to it.
Varying: the sole instance of a class

0 0
原创粉丝点击