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
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
This article introduces a design method of Java platform and Enterprise Edition (Java ee 5), which utilizes the new Java persistence API (JPA) of Enterprise JavaBeans (EJB) 3.0 ). JPA provides a standard Object link ing solution t
single-state design patterns in Java2011-09-23 16:38:46|Category: Java |Tags:technology! | Report | Font size Subscription This blog post is a blog post from a blogger called "Junny's Blog". Feel this blog is really good, so take it out here to share! (I just made a few changes to the code.)A concept:Design pattern: The
, 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
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:
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
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 ()
("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
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.