(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
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
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的微博发
23 Design Patterns and 7 major principles in Java
Create type Mode 5
Abstract Factory mode (abstract Factory pattern): Provides an interface for creating a family of related or dependent objects without specifying a specific class.
Generator mode (Builder pattern): Encapsulates a product's construction process using the builder pattern and allows you to constru
Java and design patterns in Spring practice-collection
Spring practice
Labels: Java and Design Patterns
Junit Integration
Previously used multiple times@RunWithAnd@ContextConfigurationAdd these two annotations to the test clas
, and if the encapsulation is not important. --------------------------------------------------------------------------------------------- ----- Seven design principles: 1. Single RESPONSIBILITY PRINCIPLE: one class is responsible for one responsibility.2, the Richter replacement principle "LISKOV SUBSTITUTION PRINCIPLE": Inheritance and derivation of the rules.3, the dependency inversion principle "dependence inversion PRINCIPLE": high-level mo
give a code to implement the Registrar. The benefit of creating a singleton pattern with the registrar mechanism is that it is easy to manage and can control multiple different types of singleton instances at the same time.
Summary
1. The singleton model can be easily expanded to produce a specified number of instances.
2. In the design Patterns Java Companio
layer, they have to communicate through the interface, this layered mode in the software design with a lot of, must be paid attention to.3) In each layer, there are many small modules, a small module external should also be a whole, then a module external should also provide interfaces, other places need to use the function of this module, should be through this interface.2. Parameters and return values in the interface definition:1) The interface mu
that makes external objects not new related instances, * This particular note, be sure to provide a default privatization method to override the default constructor method otherwise, if the user goes directly to the new object * , there is no guarantee of a single case ~ ~ ~ 3. Design mode of a hungry man in the process of initializing the class will complete the initialization of the relevant instance, generally think that this way to be more
. /***/Publicclass Singleton {privatestatic New Singleton (); Private Singleton () {} Public Static synchronized Singleton Getsingleton () { return Singleton; }}The creation of a single piece in the static initializer guarantees thread safety. Of course, this approach works for applications that always create and use a single instance, or that the burden of creating and running is not too heavy.3, a relatively better way is: with "Double check lock", in Getsingleton ()
thread-safe/* Type: A hungry man mode */public class Singleton {//1. Privatization of the construction method, not allowing external direct creation of the object private Singleton () {}//2. Create a unique instance of the class, using the private static modifier private static Singleton instance=new Singleton ();//3. Provides a method for obtaining an instance, using public static to decorate public static Singleton GetInstance () {return instance;}}Lazy mode: Class loading when not to create,
principle.DisadvantagesEach different implementation needs to define a subclass, which causes the number of classes to increase and the design to be more abstract.Applicable ScenariosIn some classes of algorithms, the same method is used, resulting in code duplication. Control subclass extensions, subclasses must adhere to algorithmic rules.More Design Patterns:
("Internet browsing information! "); } } Class Proxy implements network {//proxy Internet private network network; Public Proxy (Network network) {//Set the real operation of the agent this.network = Network;//Set the subclass of the proxy } public void Check () {//Body Verification Action System.out.println ("Check if the user is legal! "); } public void browse () { this.check ();//Invoke specific proxy business Op
rely on its abstraction; abstraction should not depend on detail; detail should be dependent on abstraction. That is, for interface programming, do not program for implementation.4, the interface isolation principle "INTERFACE segregation PRINCIPLE": Establish a single interface, do not set up a huge bloated interface, as far as possible to refine the interface, the interface of the method as little as possible.5. Dimitri law "low of DEMETER": Cohesion Poly.6. Open Close PRINCIPLE: A software e
about the classes it relies on. That is to say, for a dependent class, no matter how complex the logic, as far as possible to encapsulate the logic inside the class, outside the public method provided, not to disclose any information.6. Open Close PRINCIPLE: A software entity such as classes, modules, and functions should be open to extensions and closed for modification.7, combination/aggregation multiplexing principle "composition/aggregation reuse Principle (CARP)": Try to use combination an
=
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
singletonholder.instance, causing the Singletonholder class to be initialized, and when the class is loaded and initialized, it initializes its static domain to create an instance of singleton, because it is a static domain, so only when the virtual machine loads the class Initialized once and is guaranteed to be thread-safe by a virtual machine.The advantage of this pattern is that the GetInstance method is not synchronized and only performs a domain access, so deferred initialization does not
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.