creational design patterns in java

Want to know creational design patterns in java? we have a huge selection of creational design patterns in java information on alibabacloud.com

The mediator pattern for Java design patterns

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

10 of 23 Design Patterns in Java-bridge pattern

Abstract class Vehicle{Vehicleimpl Avehicleimpl=null;Public Vehicle (Vehicleimpl Vehicleimpl){Avehicleimpl=vehicleimpl;}void Transport (){Avehicleimpl.transportimpl ();}}Interface Vehicleimpl{void Transportimpl ();}Class Transportpeople implements Vehicleimpl{public void Transportimpl (){System.out.println ("people");}}Class Transportgoods implements Vehicleimpl{public void Transportimpl (){System.out.println ("goods");}}Class Car extends Vehicle{Vehicleimpl Avehicleimpl=null;Public Car (Vehicle

4 of 23 Design Patterns in Java-singleton mode (singleton pattern)

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

23 Design Patterns in Java 13-combined mode (composite pattern)

("-");}System.out.println (New String (SB) + this.getname ());For (company Company:acompanylist){Company.disp (depth + 2);}}}public class Compositepatterntest{public static void Main (string[] args){Company Parentcompany=new Concretecompany ("Anhui head Office");Company Suzhoubranchcompany=new Concretecompany ("Suzhou branch");Company Bengbubranchcompany=new Concretecompany ("Bengbu branch");Company Hefeioffice=new Office ("Hefei Office");Parentcompany.add (Suzhoubranchcompany);Parentcompany.ad

16 of 23 Design Patterns in Java-visitor mode (visitor pattern)

Import java.util.ArrayList;Import java.util.List;Abstract class Ivisitor{public abstract void Visit (Banana Banana);public abstract void visit (rice);public void Visit (ielement ielement){System.out.println ("What, how to eat?") ");}}Class Human extends Ivisitor{public void Visit (Banana Banana){System.out.println ("Human clawed Skin eats bananas");}public void visit (rice){System.out.println ("Human with tools to eat rice");}}Class Monkey extends Ivisitor{public void Visit (Banana Banana){Syste

The observer pattern for Java design Patterns

) {this.open = open; } public float Getlow () {return low; } public void Setlow (float low) {this.low = low; } public float Gethigh () {return high; } public void Sethigh (float high) {This.high = high; } public float Getclose () {return close; } public void Setclose (float close) {this.close = close; } public void Setstockdata (float open, float low, float high, float close) {this.open = open; This.low = low; This.high = high; This.close = close

Dynamic proxy for Design patterns (JDK dynamic proxy implementation in Java)

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

Java common Design Patterns-Singleton mode

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

Java Multithreading about consumer/producer Design Patterns

, - //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

A single-instance pattern of Java design Patterns in registered Singleton

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

The creation pattern of Java design patterns

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 {

The mediator pattern for Java design Patterns

http://www.verejava.com/?id=16999137231072Package Com.mediator.theory;public class testmediator{public static void Main (string[] args) {mediator Medi Ator=new Mediatorimpl (); Mediator.handle ("Rent"); Mediator.handle ("Sale"); }}package Com.mediator.theory;public interface mediator{public void handle (String content); Package Com.mediator.theory;public class Mediatorimpl implements mediator{private HouseOwner owner1; Private HouseOwner Owner2; Public Mediatori

------Builder Mode for Java 23 design Patterns

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

-----Bridging mode for Java 23 design Patterns

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 Java

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

Java Design Patterns

/2468499.html Proxy Mode http://www.cnblogs.com/java-my-life /archive/2012/04/23/2466712.html Behavioral typeResponsibility chain Mode http://blog.csdn.net/zhouyong0/article/details/7909456Command mode http://www.cnblogs.com/java-my-life/archive/2012/06/01/2526972.htmlInterpreter Mode http://www.cnblogs.com/java-my-life/archive/2012/06/19/2552617.htmlIterative m

The builder pattern for Java design patterns

my Code slice public class man { private string head; private string body; private string foot; public String gethead () { return head; } public void Sethead ( String head) { this.head = head; } public String getbody () { return body; } public void Setbody ( String body) { this.body = body; } public String getfoot () { return foot; } public void Setfoot (String foot) { This.foot = foot; }}[Java] View plaincopyprint? To see code s

A very interesting pdf for learning Java Design Patterns

");/** 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

Introduction to Java common design patterns and factory models

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

Example code for explaining state design patterns in Java

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

Total Pages: 15 1 .... 11 12 13 14 15 Go to: Go

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.