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
Single-Case mode:1: Lazy TypePackage com.design;/* 1: Lazy type */public class Singleton {/*** Private, do not allow instances to be obtained externally through singleton.instance* Static method can only access static variables.*/private static Singleton instance;Private, not allowed to instantiate externallyPrivate Singleton () {}/*** Multithreading calls this method, it is possible to create more than one instance, need to synchronize, but pay attention to the efficiency problem* 1.instance is
, - //so the wake-up process is blocked, and if the consumer thread wakes up, the consumer thread starts to work) theSystem.out.println (Thread.CurrentThread (). GetName () + "production of a product current surplus quantity:" +curnum); the Try { theThread.CurrentThread (). Sleep (250);//control the speed of production the -}Catch(interruptedexception e) { the e.printstacktrace (); the } the}Else{94 the Try { t
Package Creation _ Singleton mode _ registration; Import Java.util.hashmap;import java.util.map;/** * Registered Singleton actually maintains an instance of a set of singleton classes that store these instances in a MAP (register) *, For a single case that has already been registered, it is returned directly from the factory and, for non-registered, first registered, then * returned * @author PP * */public class Regsingleton {/** * register, to hold all registered instances */ private stat
that replaces the new operation with a factory method . (Decide which instance to create based on incoming parameters)Chestnuts:Abstract product role public interface Car {public void drive (); }//Specific product role one public class Benz implements Car {public void Drive () {System.out.println ("Driving B Enz "); }}//Specific product role two public class BMW implements Car {public void Drive () {System.out.println ("Drivi ng BMW "); }}//factory class Role public class Driver {
First, the builder model(Builder)The factory class pattern provides the pattern of creating a single class, while the builder pattern is to centralize the various products to manage, to create composite objects, so-called composite objects that refer to a class that has different properties, in fact the builder pattern is the combination of the previous abstract factory pattern and the last Test. Let's look at the code:As before, a sender interface, two implementation classes MailSender and Smss
Method () {
System.out.println ("This is the second sub!");
}
}
Define a bridge that holds an instance of sourceable:
publicabstractclassbridge{
private sourceablesource;
public Voidmethod () {
source.method ();
}
publicsourceablegetsource () {
returnsource;
}
publicvoidsetsource (Sourceablesource) {
this.source=source;
}
}
public class Mybridge extends Bridge {
single-state design patterns in Java2011-09-23 16:38:46|Category: Java |Tags:technology! | Report | Font size Subscription This blog post is a blog post from a blogger called "Junny's Blog". Feel this blog is really good, so take it out here to share! (I just made a few changes to the code.)A concept:Design pattern: The
");/** The problem is: Zhao Yun actually do not know is that strategy ah, he only know to dismantle the first bag,* And do not know is backdoor this ingenious idea, how to do? It seems that this strategy model has already written out the name of the stratagem.*Wrong Backdoor, Givengreenlight, Blockenemy is just a code, you write first, second,Third, no one will say you're wrong!** The advantage of the strategy model is that it embodies the characteristics of cohesion-poly-low coupling, the disad
JavaWhat are the common design patterns? Describes the Factory mode. Total at species, divided into three categories: creation, structural, behavioralI only remember the usual ones. 6 , 7 species, respectively:Created (Factory, factory method, abstract factory, Singleton)Structural type (packaging, adaptors, combinations, proxies)Behavior (Viewer, template, strategy)then talk about your understanding of th
the book to implement the two patterns is completely different (I think this implementation is somewhat arbitrary). the state mode, in particular, uses a separate implementation hierarchy, but I don't think it's necessary unless you assume that the implementation code is not controlled by you (which is, of course, a possibility, but if the code is controlled by you, It is also more concise and practical with a single base class). In addition, the pro
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.