I. Overview Concept
Decoupling abstraction from implementation so that abstractions and implementations can run independently
UML diagram Role: role Relationship Second, practice Set up the appropriate classes according to the roles above Abstract roles/**@author Administrator * **/publicabstractclass Abstraction { protected implenmentor impl; Public void operation () { impl.operationimpl (); }} Correcting abstract roles/**@author Administrator *
Reprint Please specify source: http://blog.csdn.net/lhy_ycu/article/details/39805735Appearance mode (facade): To resolve dependencies between classes and classes, like spring, you can configure the relationship between classes and classes into a configuration file, and the appearance pattern is to add theirRelationships are placed in a facade class, reducing the degree of coupling between classes and classe
(the same adapter can adapt both the source class and its subclass to the Target Interface ).The Object Adapter allows the target and adaptee to be completely independent. Only the adapter knows whether the target and adaptee exist.The class adapter is described below.The Object Adapter only inherits the target, but the adapter can also inherit the adaptee. Because Jav
Use
Observer Mode (Observer)
The Observer pattern defines a one-to-many dependency that allows multiple observer objects to listen to a Subject object at the same time.This subject object notifies all observer objects when the state changes, enabling them to automatically update themselves.
The Observer pattern is aBehavioral Patterns。structureFigure-Viewer
I. OverviewCapture the internal state of an object without destroying it, and save the state outside the object so that it can be restored to its previously saved state. It is an object-behavioral pattern .Second, the application scenario1, similar to the implementation of the Undo function, save an object at a certain time part of the state or all the state, when it is needed later can be restored to the previous state.2, the object's historical stat
language, can be a basic data type, can be a user-defined type, can also be a null type (void), and if it is a construction method, no return value type.
Example
This diagram class is named demo, which has four methods of operation:
The visibility of the action method is private (-), with a parameter par of type object, and a return value of type int;Operation Method1 Visibility is public (+), no parameters, return value
1 overviewThe single example pattern has several benefits:
(1) Some classes are created more frequently, and for some large objects, this is a large system overhead.
(2) eliminates the new operator, reduces the system memory usage frequency, reduces the GC pressure.
(3) Some classes, such as the core trading engine of the exchange, control the transaction flow, if the class can create multiple words, the
, it communicates with its intermediaryClass diagram:Example:Mediator public abstract class Mediator { public abstract void notice(String content);}Concretemediator Public class concretemediator extends mediator {private colleaguea CA; private colleagueb CB; Public concretemediator () {CA = new colleaguea (); Cb = new colleagueb ();} public void notice (string content) {If (content. equals ("boss") {// T
Suppose we are playing an instant strategy game. We design a soldier. He was an infantry when he was just produced, but he can switch weapons. The first switch will become an archer, the second switch will become an armored soldier holding a shield, and the third switch will become an infantry ...... How to implement this switching mechanism? At the beginning, we will think that adding a switch statement to the infantry class is not conducive to code
attack power value and color to generate a weapon, and finally return the generated weapon. The Java code is as follows:
Class Weapon {private String color; private String name; private int attack; public String getName () {return name;} public int getAttack () {return attack;} public String getColor () {return color;} public void setAttack (int _ attack) {attack = _ attack;} public void setName (String _
Java Basics _ Inner classes: In Java, a class can be defined inside another class or inside a method, such that a class is called an inner class.The primary role of inner classes: using internal classes can reduce naming conflicts.Define location: An inner
();} class FlyweightMapItem implements FlyweightItem {String name; public FlyweightMapItem (MapItem map) {this. name = map. name;} public void draw () {System. out. printf ("Drawing % s \ n", name) ;}} class MapItem {String name; public MapItem (String name) {this. name = name ;}} class FlyweightMapFactory {private static FlyweightMapFactory flyweightMapFactory
Behavioral pattern is mainly the abstraction of responsibility and algorithm. Behavioral patterns are not just about classes and objects, but about the interaction between them. Behavioral patterns are divided into two types: behavioral patterns of classes and behavior patterns of objects.
The behavior pattern of the classThe behavior pattern of a
getinstance () {return manager ;} /*** permission for storing logon users */private Map
Simulate a database to save employee information:
Public class testdb {public static collection
The specific implementation is implemented in this example based on Android. Java only writes a test class to implement it in main:
Securitymanager manager = securitymanager. get
Profile
Design pattern is an art, if you really understand the art, you will find that the world will become more beautiful.
Defined
Defines an interface for creating an object, letting its subclasses decide which class to instantiate
Working with scenes
You can use Factory mode for any place where you use complex objects
Uml
1. Abstract Factory
Abstract Factory: We all know that factories, genera
Today, I reread the template method mode, the temperature is known new.
She is a basic technology based on inherited code reuse, and her structure and usage are also the core of object-oriented design.
Java aspect Application: In the Selvert is used.
Naming convention: The name of the hook method should begin with do.
You'll get a deeper understanding when you go to see the data yourself.
There are questions to ask here.
Interesting insights into d
On the internet to find a lot of this model of information said is not thorough, looked at half a day is foggy. Had to study one by oneself.Prototype mode is a creation design pattern that returns a new instance by copying an existing instance, rather than creating a new instance. The copied instance is what we call a prototype, which is customizable.Prototype patterns are used to create complex or time-consuming instances, because in this case, copyi
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.