Creation Mode learning Summary-design mode learning notes

Source: Internet
Author: User

1. Creation Mode

1. The Creation Mode abstracts the instantiation process.

Creates and combines objects, indicating they are independent of the system. A class creation mode uses inheritance to change the object to be instantiated,

The Creation Mode of an object is to delegate Instantiation to another object, so as to avoid the non-scalability brought by hard encoding and the inability to flexibly cope with changes,

To reduce the complexity of re-changing, combining, or merging the relationships between objects.

The Creation Mode solves the problem of Object Instantiation: Who created the object and how to create it ......

Comparison Between Two creation Modes

1. abstractfactory mode:

Provides an interface for creating a series of related or mutually dependent objects without the need to define their specific classes.

Create a complete product and entrust it to abstractfactory to split the entire product into many related or mutually dependent parts,

Each part of the product can be expanded and changed. abstractfactory must provide an interface for creating each part of the product in the complete product creation process.

The client needs to use these interfaces to create various parts of the product to form a complete object. Therefore, abstractfactory reflects the relationship between a part and the whole.

2 build mode:

Separates the construction of a complex object from its representation, so that the same creation process can create different.

The construction of complex objects is embodied in the use of a ditector, which is used to create various parts of the object for different builder,

There are relatively large differences between them. Director encapsulates this complexity, so that the same process can process different complex logic, but get different representations.

3 factorymethod mode:

Defines an interface used to create objects, so that the subclass determines the class to be instantiated. Delay a class instance to its subclass.

This statement is really hard to understand. The previous modes all seem to be able to implement the function described by it: The subclass decides to instantiate the class.

It is possible that factorymethod is more focused on the creation of independent objects. Subclass is only used to create objects. These objects can be related, irrelevant, or of the same significance ......

4 prototype mode:

Use a prototype instance to specify the type of objects to be created, and create new objects by copying these prototype instances.

Create a new object by yourself. Under what circumstances is this necessary? This is really hard to understand.

Imagine why replication makes some operations simple ...... HoweverCodeIs it as simple as copying?

It may be used in the framework to simplify the creation and initialization of similar objects, or to capture the runtime information of an object ......

5 Singleton mode:

Ensure that a class has only one instance and provides a global access point.

 

I have a low understanding of these models. They are purely personal prejudice. Please give me more advice!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.