Java and mode Reading Notes, Java mode Reading Notes

Source: Internet
Author: User

Java and mode Reading Notes, Java mode Reading Notes

Design goals: scalability, flexibility, and insertion ability.

Design principles

● Open Closed Principle

It is open to extensions and closed to modifications.

For object-oriented languages, the abstraction layer of the system cannot be changed, but the Implementation Layer of the system can be expanded.

● Internal replacement principle

Where any base class can appear, subclass can certainly appear.

● Principle of dependency reversal

It depends on abstraction rather than implementation.

● Merging/combination principles

Try to use combination instead of Inheritance

● Dimit's Law

The entity of a software should reduce interaction with other entities.

● Interface isolation principle

Small separate interfaces should be provided.

Abstract class

● Abstract classes should have as much code as possible.

● Abstract classes should have less data.

Creation Mode: abstraction of the class instantiation process.

● Class Creation Mode: the class creation mode uses the inheritance relationship to delay the class creation to the subclass. This encapsulates the information about the specific classes that the client will obtain.

● Object Creation Mode: dynamically delegates the object creation process to another object. In this way, the client dynamically obtains instances of specific classes.

Simple Factory)

● Factory role (Creator): The factory class creates product objects under direct calls from the client. He often has a specific Java class implementation.

● Abstract Product role: it is the parent class of all created objects or a common interface. Abstract product roles can be implemented using a Java interface.

● A specific Product role (Concrete Product): Any role created is an instance of this object. Specific java class implementation.

Factory Method)

● Define a factory interface for creating product objects and postpone the actual creation to subclass.

● Abstract Factory role (Creator): it is irrelevant to the application. Any factory class that creates an object in the mode must implement this interface.

● A specific factory role (concreaor): implements an abstract interface, which is closely related to the logic of the application. It is called by a program to create product objects.

● Abstract Product role: it is the parent class of all created objects or a common interface. Abstract product roles can be implemented using a Java interface.

● A specific Product role (Concrete Product): Any role created is an instance of this object. Specific java class implementation.

Abstract Factory)

● The Factory method mode corresponds to a product level structure. Abstract factories correspond to multiple.

● Abstract Factory role (Creator): it is irrelevant to the application. Any factory class that creates an object in the mode must implement this interface.

● A specific factory role (concreaor): implements an abstract interface, which is closely related to the logic of the application. It is called by a program to create product objects.

● Abstract Product role: it is the parent class of all created objects or a common interface. Abstract product roles can be implemented using a Java interface.

● A specific Product role (Concrete Product): Any role created is an instance of this object. Specific java class implementation.

Singleton mode (Single)

● A class has only one instance.

● Create an instance by yourself.

● Provide instances to the entire system.

Builder)

● Separate the internal appearance of a product from the production process, so that a product object with different appearances can be generated during the construction process.

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

●

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.