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
本文深入探讨了面向对象编程中用于定义对象创建方式的创建型设计模式,包括工厂方法、抽象工厂、构建者、原型和单例模式等。通过详细解释这些模式的应用场景、工作原理和优点,帮助开发者更好地理解和应用这些模式来提高代码的可维护性和灵活性。
400

被折叠的 条评论
为什么被折叠?



