There are 23 common Java design patterns:
Creation Mode
1. Factory method ):
Defines an interface for creating objects, so that the subclass determines which class to instantiate. Factory method delays the instantiation of a class to its subclass.
2. Abstract Factory ):
Provides an interface for creating a series of related or mutually dependent objects without s
definition : Allows an object to change its behavior when its internal state changes. The object appears to have modified its class.Nature : Separates and chooses behavior according to state.State : The property value of the object instance.behavior : The function of an object is mostly mapped to a method.the function of State mode : The behavior of separating state, by maintaining the change of state, to invoke different functions corresponding to different states.States and behaviors are assoc
State Interface Classpublic interface State {void handle ();}Bookedstate class/** * Booked Status * @author Administrator * */public class Bookedstate implements state {@Overridepublic void handle () {SYSTEM.O Ut.println ("Room has been booked! Nobody else can fix it! ");}}Checkedinstate class/** * check-in Status * @author Administrator * */public class Checkedinstate implements state {@Overridepublic void handle () {Syste M.out.println ("Room has been checked in!" Please do not Disturb! ");}}F
Banktemplatemethod Abstract classPublic abstract class Banktemplatemethod {//Concrete method public void Takenumber () {System.out.println ("queue");} public abstract Void Transact (); Transact specific business//hook method public void Evaluate () {System.out.println ("Feedback Score");} Public final void process () {//Template Method!!! This.takenumber (); This.transact (); This.evaluate ();}}Test class Clientpublic class Client {public static void main (string[] args) {Banktemplatemethod BTM
1. Singleton mode: For the entire life cycle of an application, only one instance of the Singleton class is available and is automatically instantiated. The constructor method for a singleton class must be private and provide a global access pointpublic class Test { private test () {} private static test uniqueinstance = new test (); public static Test Getuniqueinstance () { return uniqueinstance; }}2. Factory mode:(1) Simple Factory mode: The factory class can return instance
();} }Customer class:public class Customer {public static void Main (string[] args) { FactoryBMWX1 x1 = new FactoryBMWX1 (); X1.selectengine (); X1.selectaircondition (); FactoryBMWX7 x7 = new FactoryBMWX7 (); X7.selectengine (); X7.selectaircondition (); }}Multiple factory roles are available for multiple product roles, each specific factory role is only instantiated for one product role, and each specific factory class is responsible for crea
What is the adaptation class for java-7.6 adaptation design patterns? Or the adaptation interface?
In this chapter, let's discuss the adaptation issue?
To put it bluntly, you can use any object to call a method, and this object only needs to comply with certain protocols.
The implementation of this protocol has two methods: inheritance and interface, but interfac
Method.invoke (Userdao, args);}} ); U.add (user);}Parameter description:Proxy.newproxyinstance (loader, interfaces, h)Loader: Class loader, passing in the object you want to proxy, through the object name. GetClass (). getClassLoader () to get the class loader for the object.Interfaces: A collection of all implemented interfaces of the Proxied object Invocationhandler is the interface that is implemented by the calling handler for the proxy instanceImplement Invcationhandler's Mi Ming inner cl
("2");Wuyi } the - @Override Wu PublicProduct getproduct () - { About returnproduct; $ } - } - - Public classDirector A { + PrivateFactory Factory =Newfactory1a2b (); the - PublicProduct newproduct () $ { the factory.init (); the Factory.buildparta (); the FACTORY.BUILDPARTB (); the returnfactory.getproduct (); - } in } the the Public classTest About { the Public Static voidMain (string[] args) the { theDirector Director =NewD
staff A's needs to the target staffStaff B receives a request from staff A: this information needs to be operated by Staff BStaff C Initiates demand: This information requires B staff to signThe manager received the request from Clerk C: This information needs to be signed by Clerk B.The manager sends the staff C's needs to the target staffStaff B receives a request from Clerk C: This information needs to be signed by Clerk B.As listed above, staff A and employee C are required to request staff
As an object's creation mode, Singleton mode ensures that a class has only one instance, and instantiates itself and provides this instance to the system as a whole.A singleton class can have only one instance.The Singleton class must create its own unique instance.The Singleton class must provide this instance to all other objects.Typically, the constructor is described by private, prohibiting the external construction of the object and obtaining a unique instance through getinstance.Class Sing
method.Where the member variable object target represents the object being proxied. In the same way, it is injected through the constructor of the dynamic proxy class.Emphasis: The 1th parameter of the Invoke method is not used by object proxy. PackageCom.liwei.dynaproxy;ImportJava.lang.reflect.InvocationHandler;ImportJava.lang.reflect.Method;/*** Dynamic proxy class, this is a processor * *@authorAdministrator **/ Public classDynaproxyImplementsInvocationhandler {PrivateObject Target;//The obj
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.