enterprise design patterns java

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

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 {

The observer pattern for Java design patterns

This. subjectstate =subjectstate; the This. Notifyobservers (); + } - } $ $ Import Staticjava.lang.System.out; - Public classConcreteobserverImplementsObserver - { the PrivateString observerstate; - Wuyi Public voidUpdate (Subject Subject) the { -Observerstate =((ConcreteSubject) subject). Getsubjectstate (); Wu } - About Public voidinfo () $ { -Out.println ("I am:" +observername); -Out.println ("Info:" +observerstate); - out.println (); A

The builder pattern for Java design patterns

mode, one part is the component construction and the product assembly, the other part is the overall built algorithm . It is important to recognize this because in the construction model, the emphasis is on fixing the overall built algorithm, while flexibly extending and switching the specific construction of the part and the way the product is assembled.To put it bluntly, the focus of the construction model is to separate the construction algorithm and the concrete construction implementation,

Observer pattern for design patterns (Java built-in)

Displayelement.java,weatherstation.java Ibid.Weatherdata.javaImportjava.util.Observable; Public class weatherdata extends Observable { Private floattemperature;Private floathumidity;Private floatpressure; Public float gettemperature() {returntemperature; } Public float gethumidity() {returnhumidity; } Public float getpressure() {returnpressure; } Public Weatherdata() { } Public void measurementschanged() {setchanged (); Notifyobservers (); } Public void setmeasurements(floatTemperature

The mediator pattern for Java design patterns

); Colleague2 colleague2=new Colleague2 (mediator); Mediator.setcolleague1 (colleague1); Mediator.setcolleague2 (colleague2); Colleague1.send ("How are you doing?" "); Colleague2.send ("Not bad"); } }The intermediary mode applicable scenario A set of objects communicates in a well-defined but complex way. The resulting interdependence structure is confusing and difficult to understand. An object that references many other objects and communic

Decorator mode for Java design patterns

Application Scenarios for Adorner mode:1, need to extend the functionality of a class.2, dynamic for an object to add functionality, but also can be dynamically revoked. (Inheritance cannot do this, the inherited functionality is static and cannot be dynamically deleted.) )Source interface:1 Public Interface sourceable {23 void method (); 4 }SOURCE class:1 Public class Implements sourceable {2 @Override3public void Method () {4 System.out.println ("Source.method () ..."); 5

Producer and consumer model--java design Patterns

=Newproductor (product);5 Pool.submit (proc);6Productor PROC2 =Newproductor (product);7 Pool.submit (PROC2);8ListNewArraylist();9 for(intI =0;i){TenCustomer cus =NewCustomer (product); One Cusgroup.add (cus); A pool.submit (cus); - } -Thread.Sleep (1000*1); theProc.stopproc ();//Termination of production -Proc2.stopproc ();//Termination of production -Cusgroup.foreach (Cus-cus.stop ());//Close Customer -Proc.stop ();//Close the producer, (Close the consumer first, or the consum

Java Design Patterns Rookie series (22) The model and implementation of the mediator pattern

house. By them choose the house they want */@Overridepublic void Recommendhouse () {zhangsan.selecthouse (); Lisi.selecthouse ();}} /** * Client Test class * * @author Leo */public class Test {public static void main (string[] args) {Mediator mediator = new Myme Diator (); Mediator.createmediator (); Mediator.recommendhouse ();}}Iii. SummaryThe mediator pattern only needs to concern with the Mediator class relationship, the relationship between the detailed class and the class and the call to m

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.