the agent { SYSTEM.OUT.PRINTLN ("Business logic output------------completed before--------------Agent");} Custom method: The agent finishes after the logical private void Postrequest () {System.out.println ("--------------the agent completes the business logic output-------------");} Main method public static void main (string[] args) {Proxysubject proxysubject = new Proxysubject ();p roxysubject.request ();}} Copyright NOTICE: This article for Bo Master original article, without Bo Master perm
Feel the code is awkward, turn back to the Java 23 design patterns.Today, well, it's so late, sleepy. Let's get a simple singleton pattern.Single-case mode: Commonly known as single dogPackage Singleton;public class SingleTon {Private static Final class Singletonbuilder {private static SingleTon SingleTon = new SingleTon ();}Private SingleTon () {}public static SingleTon getinstance () {return Singletonbuil
1 //application of the interface: the design pattern of the factory method2 public classTestfactorymethod {3 public Static voidmain (string[] Args) {4Iworkfactory i =Newstudentworkfactory ();5 i.getwork (). doWork ();6 7Iworkfactory I1 =Newteacherworkfactory ();8 i1.getwork (). doWork ();9 }Ten } one a Interfaceiworkfactory{ - work getwork (); - } the classStudentworkfactoryImplementsiworkfactory{ - - @Override - publicwork ge
makedifferentfunction ();Define abstract methods to complete different production details (phones of different colors)protectedAbstract void makedifferentcolor ();Define abstract methods to complete different production details (different types of phones)protectedAbstract void makedifferenttype ();}/*** Create real implementation classes to achieve specific production details**/class Concreteclass extends abstractclass{Methods to implement abstractions in the parent classprotected void Makediff
Combinatorial mode is a common design pattern for maintainability-oriented programming. Simply put, a class contains a set of collection of the current class as attributes of the class. This is a certain similarity to recursion. His goal is to establish a tree hierarchy between objects of the same type, and an upper object can contain multiple downlevel objects. For example, a menu can have many options, and these options may contain the next level of
Common Java class libraries-Observer design patterns (Observable class Observer Interface) and observableobserver
Link: http://www.2cto.com/kf/201310/253013.html
To implement the Observer mode, you must rely on the Observable class and Observer interface provided in the java. util package.
1234567891011121314
"); Customer Lisi = new Customer ("John Doe"),/** * Join Customer */food.addobserver (Zhangsan); Food.addobserver (Lisi);/** * update Price */ Food.setprice (1.5f);}}third, the application scenarioGUI frame, meteorological observation, etc.Iv. SummaryBe sure to call the Setchanged () method before notifying all observers to set the state of the observer to be changed so that notifyobservers () will not be updated with the Observer Update method. The above assumes that there are different views o
actually maintains an instance of a set of singleton classes that are stored in a map (the register), returned directly from the map for an instance that has already been registered, and then registered and returned, if not registered. A hungry man and lazy-type differenceThese two look very similar at first glance, in fact there is a difference, the main two points1. Thread Safety:A hungry man-type is thread-safe, can be used directly for multithreading without problems, lazy-style is not, it
race is what race, burn bar for (int i=0;ipublic class Classutils {//to an interface that returns all implementation class public static listThe factory method model also has a very important application, that is, deferred initiation (lazy initialization), what is deferred initialization?When an object is initialized, it is not released, and when it is used again, it is not initialized again, directly from the memory to get it,How to achieve it, very simple, see examples:public class Humanfacto
of the subclass is given to the decorator class at the client. is an alternative to inheritance2) Implementation: (The IO stream will wrap the file into an efficient character stream) publicinterfacephone{voidcall ();} publicclasscallphoneimplementsphone{@Overridepublic voidcall () { SYSTEM.OUT.PRINTLN ("call");}} publicclassphonedecorateextendscallphone{privatephonephone;public Phonedecorate (Phonephone) {super (); this.phone=phone;} @Overridepublic voidcall () {phone.call ();}} Publicclassmus
objects, and be able to manipulate the interaction between objects more flexibly.SummarizeIn object-oriented programming, a class is bound to have dependencies on other classes, and completely independent classes are meaningless. It is also quite common for a class to rely on multiple classes at the same time, since there is a case that a one-to-many dependency has its rationality, and proper use of the mediator pattern can make the original messy object relationship clear, but if abused, it ca
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,
); 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
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.