implements operator{@Overridepublic double Operate (double A, double b) {//TODO auto-generated Me Thod Stubreturn A + b;}}public class Suboperator implements Operator {@Overridepublic double Operate (double A, double b) {//TODO auto-generated m Ethod Stubreturn A-B;}}3.provides a factory interface:Public interface Operatorfactory {public Operator createoperator ();}4. Create two factory classes:public class
Java Design Pattern builder PatternThis article continues to introduce the builder modes of the 23 design patterns series.Definition: builder mode: separates the construction of a complex object from its representation, so that different representations can be created during the same construction process.Scope 1: When creating complex objects, algorithms should be independent of the components of the object
Java design pattern (3) Visitor pattern and Application in Multi-Dispatch scenariosThe basic concept of Visitor encapsulates operations that act on each element in the data structure. Different operations can be implemented with the help of the new visitor, reducingCouplingVisitors canData StructureAndData OperationsDecoupling makes it unnecessary to modify the d
Java Design Pattern modeling and implementation of cainiao series (21) enjoy metadata Pattern
Flyweight: uses the sharing technology to effectively support a large number of fine-grained objects. The main purpose is to share objects, that is, the shared pool. When there are many objects in the system, the memory overhead can be reduced. To some extent, You can
Java Design Pattern serialization (6)-adapter Pattern
Name: Adapter
Purpose: Convert the interface of a class to another interface that the customer wants. The A d a p t e r mode makes those classes that cannot work together due to interface incompatibility work together.
Applicability:
You want to use an existing
Java Design Pattern cainiao series (13) state pattern modeling and implementation
State: allows an object to change its behavior when its internal State changes. The object seems to have modified its class. To put it bluntly, the state mode refers to the expansion of statements such as switch case, which have differe
Defined
Template method mode
Defines the skeleton of an algorithm in an operation, and completes the implementation of some of the steps in a subclass.The template method pattern allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm.
The template method pattern is one of the most common patterns in all patterns and is the basic t
=true; Setchanged (); Notifyobservers ("Late"); } PublicString toString () {returnname; }}//Teacher Class (Teacher) implements observer interface becomes observerclassTeacherImplementsobserver{//parameter arg as key, the response triggered by this parameter is stored in the map as value PrivatemapNewHashmap(); PublicTeacher () {Info.put ("Sleep", ", wakeup!wakeup!"); Info.put ("Late", ", come in."); } //to add a key-value pair Pu
Java Design Pattern modeling and implementation of cainiao series (19th) Memorandum Pattern
Memento: stores a state of an object to restore the object as appropriate.I. uml modeling:
Ii. Code Implementation
/*** Memento: The main purpose is to save a certain state of an object to restore the object when appropriate. ** example: original
Java Design Pattern cainiao series (23) Visitor pattern modeling and implementation
Visitor mode (Visitor): decouples the data structure and the operations acting on the structure, allowing the operation set to evolve relatively freely. The visitor mode is suitable for systems with relatively stable data structures and easily changed algorithms. The advantage o
Java Design Pattern modeling and implementation of cainiao series (20) interpreter Pattern
Interpreter mode (Interpreter): defines the value obtained after an operation between an object and an object. Generally, it is mainly used in the development of compilers in OOP development, so it has a narrow application scope.I. uml modeling:
Ii. Code Implementation
/
Status pattern of Java Design PatternWhen to use the State mode is usually used in actual use, so it is suitable for "status" switching. Because we often use If else if else for status switching, If the status is determined to appear repeatedly, we need to think about whether the State mode can be used. The difference between the switch status and the general status judgment is described here. The general s
first, the concept Concept UML diagram Role Usage Scenarios In fact, we often used abstract class is the pattern to use, so basically belong to a better understanding of a pattern.Second, practice According to the above role, give the corresponding code Abstract templates/*** Abstract Template * *@authorAdministrator **/ Public Abstract classAbstracttemplate {/*** Declaration and implementatio
What is the decorator pattern (decorator)?Dynamically add some additional responsibilities to an object. Decorator mode is more flexible than generating subclasses in terms of adding functionality.first, the structure
Component: defines an object interface that can dynamically add responsibilities to these objects.
Interface Component {public
void operation ();
}
Concretecomponent: Implements the interface defined by Component.
Java design pattern-constructor pattern (Builder)
The build mode is the object creation mode. The construction mode separates the internal objects of a product from the production process of the product, so that a building process can generate product objects with different internal representations.Object Construction:In some cases, an object has some important p
glad to share my knowledge.* General-purpose single-case mode*/@SuppressWarnings ("All")Public Classsingletonpattern {private static Finalsingletonpattern singletonpattern= newSingletonpattern ();Limit cannot directly produce an instancePrivatesingletonpattern () {}Public synchronized Staticsingletonpattern getinstance () {return singletonpattern;}}Direct new An object is passed to the member variable of the class Singletonpattern, when you want geti
One, the Observer pattern definition
The observer pattern is defined by:
Define a one-to-many dependency between objects so if one object changes state, all its dependents AER notified and Updated automatically.
Defines a one-to-many dependency between objects so that when an object changes state, all objects that depend on it are notified and automatically upda
The
In the WEB application deployment descriptor, the rules for mapping syntax are as follows:A string that starts with the "/" character and ends with "/*" is used for path mapping.With "*." The beginning string is used for the extension mapping.An empty string ("") is a URL pattern used to specify the exact mapping application context root, such as a request from http://host:port/The "default" servlet of the application is represented when only "/"
is actually the omission of the reality, in the practical application, the colleague class generally consists of several components, they influence each other and depend on each other. The more colleagues class, the more complex the relationship. Also, a colleague class can behave as a set of implementations that inherit the same abstract
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.