, 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
Without the idea of design, you cannot become an architect. The architect is a good piece of code, drawing a beautiful uml/prototype, wrote a technical document, more to solve the project key technology of the comprehensive talent. Architect = Front-end engineer + back-end Programmer + System Analyst + Key Technology Solutions + various technology collocation + design mode + deployment tuning + other, visib
Design in design mode, Factory method is also a relatively simple one, but the application is very broad, ejb,rmi,com,corba,swing can see the shadow of this pattern, It is one of the most important patterns. In many places we see xxxfactory classes like this, so what is factory method, why use this pattern, how to use the Jav
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
for(inti =0; I 5; i++) {Fansobserver F =New Fansobserver("Name"+ (i +1)); Fans.Add(f); Vs.Addfans(f); }//This tweet, 5 fans have received pushVs.Publish("My girlfriend is so nice!" ");//Incredibly show love, the first 2 fans, can not look down, take off! for(inti =0; I 2; i++) {vs.Removefans(fans.)Get(i)); }//This time the Micro Bo, those two take off the person will not seeVs.Publish("I want to send all my fans an iphone X"); }}Run results大V发布微博:我的女朋友真好看!name1 收到大V的微博发
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
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;
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
=
new Subscriptionsubject ();
//create user Weixinuser user1=new Weixinuser ("Yolanda Maple"); Weixinuser user2=New Weixinuser ("The Brow of the Moon"); Weixinuser user3=New Weixinuser ("Purple Xuan"); //Subscribe to public number Msubscriptionsubject.attach (user1), Msubscriptionsubject.attach (User2); Msubscriptionsubject.attach ( USER3); //Public number update sends a message to subscribers of the subscription msubscriptionsubject.notify ("Liu Wangshu's Colum
java Design PatternsDesign Pattern ClassificationThe Java design pattern can be divided into three categories according to the creation pattern, the structure pattern and the behavioral pattern:
Create pattern
Single-instance mode, Factory mode, abstract Factory mode,Builder mode, prototype mode
A single-instance pattern of Java design patternsRecently because want to understand the bottom of the source code, so looked at some design patterns, follow-up to read several kinds of writingSingle-Case Pattern English Original:
Ensure a class have only one instance,and provide a global point of access to it
(P7)It is recommended to join the software company directly, so you will learn a lot of practical things;The main development direction of programmers is the senior technical experts, whether it is Java,. Net or database domain, must first become an expert, and then may continue to evolve into an architect;enhance the initiative and participation of the work;only with a higher vision can we seek greater development;(P10)Job- hopping is required cost,
(P7)It is recommended to join the software company directly, so you will learn a lot of practical things;The main development direction of programmers is the senior technical experts, whether it is Java,. Net or database domain, must first become an expert, and then may continue to evolve into an architect;Enhance the initiative and participation of the work;Only with a higher vision can we seek greater development;(P10)Job-hopping is required cost, t
implementation for all three of these methods. Therefore, any concrete class that inherits from the abstract class Serviceadapter can choose the method implementation that it needs, regardless of the other unwanted methods. the adapter mode is intended to change the interface of the source so that it is compatible with the target interface. The default adaptation is slightly different , and it is a mediocre implementation provided to facilitate the creation of a non-mediocre adapter class.At
Recently looking at design patterns, find a good blog, explaining the various design patterns in the Java specific application scenarios, Bowen address http://blog.jobbole.com/62314/.
Structured mode:
Adapter Mode:
Used to transform an interface into another interface. Jav
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.