) {Mediator Med = new Concretemediator ();The boss is here.Med.notice ("Boss");The client is here.Med.notice ("Client");}}ResultOrdinary employees work hardFront desk attention!Applicability:1. A group of objects communicates in a well-defined but complex way.The resulting interdependence structure is confusing and difficult to understand.2. An object that references very many other objects and communicates directly with those objects makes it difficult to duplicate the object.3. Want to customi
corresponding get function. When we call them, we only need to call the Public matching code of the above parent class to obtain the correct data. The following is the code snippet after the facade mode is introduced to the above table structure: ......String name, ID, age;Studentselect student = New Studentselect ();Student.exe cute ();Name = Student. getname ();ID = Student. GETID ();Age = Student. getage ()...... The above mechanism can also be used for SQL statements updated in the
Design pattern-- Reusable Object-oriented Software Foundation (patterns)I. Classification of design PatternsIn general, design patterns fall into three broad categoriesCreation Mode: Factory method mode, abstract Factory mode, simple interest mode, builder mode, prototype mo
Design Patterns ----------- Singleton design patterns, Singleton Design PatternsHungry Chinese Style: class Single {// do it in advance! Private static final Single s = new Single (); // private constructor cannot use new to create an object! Private Single () {}// public st
I saw this article in the Java Forum. The author compared the 32 Java models in a simple language, which has a good inspiration, but unfortunately I didn't give a specific meaning, I added it to the back. These are the simplest introductions. If you want to learn them, I suggest you take a look at Dr. Yan Hong's book "Java and
Newwidgets (); - } - } - } - Public classFactoryconstraint { in Public Static voidMain (string[] args) { - NewFoo2Newintegerfactory ()); to NewFoo2Newwidget.factory ()); + } -}View CodeClassTemplate method:Another way is to use the template method design pattern, by implementing abstract class (template) abstract method to create objects, also can get compile time type check, the following is the code:1 PackageC
Decorative (Decorator) design pattern
Dynamically adding some extra functionality to an object, the decorative pattern is more flexible than generating subclasses for added functionality
The ability to dynamically extend an object without changing the original class file and using inheritance (this is the benefit of the decorative design pattern)
The decorative
If you are involved in java-related development, it is inevitable to use abstraction and encapsulation, which is a feature of java, but also every developer must master, Java is so, and so is Android. And the design pattern is to tell us how to write efficient and more applicable and extensibility of the code, recently
, creating instances*/ Public StaticSingleton getinstance () {if(Instance = =NULL) {instance=NewSingleton (); } returninstance; } /*if the object is used for serialization, you can ensure that the object remains consistent before and after serialization*/ PublicObject readresolve () {returninstance; }}This class can meet the basic requirements, but, like this no thread-safe class, if we put it into multi-threaded environment, there will be problems, how to solve? We will first
code with a template method that invokes these new operations.Controls the subclass extension. The template method invokes the "hook" operation only at a specific point, so that only those points are allowed to be extended.The source code for these design patterns is not to be made clear by a few words, so I created a Java Architecture Technology Exchange Group:
= "Http://img.my.csdn.net/uploads/201309/01/1378037235_7476.jpg"=new Webpimageloader (); Loader.downloadimage (IMAGEURL,200,200);Pattern mode Advantages and disadvantages: 1.) Advantages The template method pattern removes duplicate code from subclasses by moving the invariant behavior to the superclass. Subclasses implement some of the details of the algorithm, which facilitates the expansion of the algorithm.By invoking the subclass implementation of a parent class, the new behavior is adde
Userwang=NewUser ("Wangwu"); Server.registerobserver (Userzhang); Server.registerobserver (Userli); Server.registerobserver (Userwang); Server.setinfomation ("PHP is the best language in the world!" "); System.out.println ("----------------------------------------------"); Server.removeobserver (Userzhang); Server.setinfomation ("Java is the best language in the world!" "); }}Test results:6. Summary
This pattern i
JAVA design patterns-Singleton and singletonReprinted please indicate the source: http://blog.csdn.net/l1028386804/article/details/45441169I,Overview
Ensure that a class has only one instance and provides a global access point to it.II,
Applicability
1. When the class can only have one instance and the customer can access it from a well-known access point.
2. Whe
Jobseeker ("Mike"));
Hh.registerobserver (New Jobseeker ("Chris"));
Hh.registerobserver (New Jobseeker ("Jeff"));
Every time you add a job, all job-seeking people are notified.
hh.addjob ("Google Job");
Hh.addjob ("Yahoo Job");
}
The advantages of the Observer pattern The Observer and the observed are mildly correlated and abstract coupled so that It's easier for both to expand. The Observer pattern is a commonly used trigger mechanism that forms a chain o
I. Classification of design PatternsIn general, design patterns fall into three broad categories:Create five types of models: Factory method mode, abstract Factory mode, singleton mode, builder mode, prototype mode.Structure mode, a total of seven kinds: Adapter mode, adorner mode, proxy mode, appearance mode, bridging mode, combined mode, enjoy the meta-mode.The
handling. From the method that invokes the processor interface declaration, it can be seen theoretically that it can throw any type of exception, because all exceptions are inherited from the Throwable interface, but is it true? The answer is no, because we must obey an inheritance principle: When a subclass overrides a parent or implements a parent interface, the exception thrown must be within the list of exceptions supported by the original method. So while the calling processor is theoretic
{public double createoperation (double Numbera, Double numberb,string oper);}2, create a function of the implementation of the interface, we put this subtraction algorithm is written in this implementation class, the class can be loaded when the initialization, this way, you need to use the direct call./** * Created by LK on 2016/5/8. */public class Operationfunction {private static mapNow, the difference with non-functional is that we don't need to create a lot of implementations and create
combination of objects, and the encapsulation doesn't matter.
Seven major design principles
Single RESPONSIBILITY PRINCIPLE: one class is responsible for one responsibility.
Richter replacement principle "LISKOV SUBSTITUTION PRINCIPLE": Inherited and derived rules.
Dependency inversion principle "dependence inversion PRINCIPLE": The high-level module should not rely on the lower layer module, both should rely on its abstraction;
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.