Summary of Java Design Mode

xiaoxiao2021-03-06  44

Since J2EE has appeared, it has greatly simplified enterprise-level development under Java. However, as J2EE is increasingly being applied to various fields, developers gradually realize that a method is needed to standardize the development process of the application, and the methods they use are structural layers of standardization applications. Some of the complex technologies independent of business logic are typically encapsulated in the structural layer to establish weak connections between business logic and underlying architecture. Some design patterns will be introduced in a topic, by using these design patterns, developers can achieve standardized and simplified application development processes.

Application structure and J2EE

J2EE is a very successful technology that provides consistent standards for some basic tasks, such as database connections, distributed applications, and more. But using J2EE does not guarantee developers to develop successful applications. Some people think that J2EE itself is a framework technology, but this understanding is incorrect, we should realize that J2EE does not provide a framework that helps developers develop high quality applications, so many experienced developers pass Use design patterns to compensate for this shortage.

Design Patterns

In the circle of developers, you enrich the experience of the entire circle through the problems encountered during the development process and the solution. The design mode is produced in this case. A design pattern is inevitably for a particular problem, this problem solution and the consequences of solving this problem. In the process of solving the problem that occurs in program development in J2EE, people divide the design model into two categories, one is a general development mode, one is to solve a specific J2EE problem mode. Let's take a look at what is the development model of each type.

J2EE design mode

J2EE design model has grown with Java developers in the past few years. These design patterns are proposed for issues that may occur when using various J2EE technologies, they can help developers to construct the requirements of the application framework. For example, the Front Controller mode transforms the development of servlet code to development under the graphical user interface. But you need to remember that the J2EE design model solves the most likely problems in the J2EE project. If you encounter in J2EE, it is very special, it is very likely that there is no corresponding design model to solve it.

Software development design model

Software development design modes are divided into two, one is a general-oriented object design mode. For example, a factory mode is an object-oriented design pattern that encapsulates the object to enable objects to reuse, so that the system resource occupied by the program can be reduced. The other is based on Java design patterns, and these design patterns are either combined with Java's language characteristics, or object-oriented technology in Java deepening. Don't think that software design patterns are relatively independent of J2EE, think they are not important, usually they are more important than J2EE design patterns. This is because:

1) J2EE design mode is only in recent years, and in the continuous change, the software development design model has been tested for a long time, more mature and perfect than the former;

2) Some J2EE design patterns are based on some software development design patterns;

3) Software development model provides a solid foundation for J2EE design patterns. Its application will affect the stability and expandability of the entire structure.

In practical applications, design patterns are not a specific code. Design mode is usually described in the design manual. The real challenge to apply the design pattern to the system is how to apply the idea in the system. These ideas must be applied to the appropriate environment.

According to the problem solved by the design mode, it can be divided into the following types:

· Create type: Create type mode is used to create an instance of classes. But and through New to create an instance, these modes provide a more flexible way, which is the program to create specific classes based on a particular situation.

· Structure Type: Mode of structural types help developers more complex structures after combining simple objects together. · Behavioral type: behavioral type mode helps the development of the developer control class.

Create type mode

All modes of creation are related to how to effectively create instances of the class. In Java, if the developer wants to generate an instance of a class, the easiest way is to use the New keyword:

Myfoo = new foo (); // Generate an instance of a Foo

This method can only generate a fixed class in the program. However, in many cases, the program needs to generate different classes of different classes according to different situations, which requires an instance of the generation process to generate the instance to a special creation class, which is determined by this class. This makes the program better flexibility and versatility.

Create types of modes include:

· Factory Pattern: The class implemented according to the factory model can generate an instance of a class in a set of classes in accordance with the data provided, and this set of categories has a public abstract parent class.

· Abstract factory pattern: Abstract factory model can also generate an instance of a class in a set of classes in a set of data provided, and this set of categories has a public abstract parent class. Just it defines an interface.

• Builder Pattern: The constructor mode separates a complicated object's construction process and its performance layer, so that different expressions can be displayed depending on the situation.

Prototype Pattern: The prototype mode creates a new instance by copying the instance of the class.

• Singleton Pattern: The class implemented according to a single mode is only a class, and a global pointer is provided to reference the instance.

Structure type mode

The mode of structural types combines classes to constitute more complex structures. It is also divided into class mode and object mode. The difference between class mode and object mode is that class mode provides a valid interface by inheriting relationship; the class mode is complicated by object synthesizing or comprising more complicated structures in other objects.

The mode of structural types includes the following modes:

· Adapter Pattern: Adapter mode can match a class interface and another class interface.

· Bridge mode: Bridge mode provides a fixed interface to client programs, but allows developers to change the actual implementation class. Such developers can separate the interfaces to be separated from the specific implementation class.

• Composite mode: Composite mode can comply with multiple objects, each of which may be a simple object, or a composite object.

· Proxy Pattern: Agent mode replaces a complex object with a simple object, which will be loaded into the system when complex objects are needed, so that system resources can be saved, and the response speed of the system can be improved. This mode is useful in the network environment.

• Decorator Pattern: By modifying mode, developers can bind a particular function on the object at runtime.

• Flyweight Pattern: Lightweight Mode The data is retransmitted to the object when you save some of the data in the object in the object. Doing so can reduce a large amount of simple object occupied space.

· Positive mode (FA? ADE PATTERN): The front mode organizes the complex class hierarchy to obtain data in the hierarchy through a simple interface. Pattern of behavior type

The mode of behavior type is mainly the mode of communication between objects, including the following modes:

· Observer Pattern: Observer mode can notify multiple classes when changing.

· Mediator Pattern: The intermediary mode can control communication between several classes through a middle class, and these classes do not need to understand the other party.

· Memory mode: Memory mode can save and restore the internal state of the object without damaging the object encapsulation.

· CHAIN ​​OF RESPONSIBILITY: The duting chain mode passes the request to a set of objects, and only a specific object will process the request. This will further impair the connection between the classes.

• Command Pattern: The command mode passes the request to a specific object so that the client can send a request even if it is not known how the server is handled.

· Template mode: Template mode provides an abstract definition of algorithm.

• Strategy Pattern: Policy mode defines a set of algorithms to encapsulate each algorithm and make them interchangeably. Policy mode makes these algorithms that can change from each other when the client calls them.

· Visitor Pattern: The visitor mode passes the data in other classes through an access class.

• State Pattern: Status mode Saves a variable of a class instance in a separate memory space.

· Iteerator Pattern: Iterative Mode The data collection in the data collection is traversed by standard interfaces without knowing the internal expression of the data.

转载请注明原文地址:https://www.9cbs.com/read-71560.html

New Post(0)