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.
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●