Introduction to Design Patterns
Each pattern describes a recurring problem around us, as well as the core of the solution to the problem.--Christopher Alexander
The design pattern describes a general solution to a common problem in the software design process. Object-oriented des
); }/** * Will gather the observers to empty */public synchronized void Deleteobservers () {obs.removeallelements (); }/** * Set "changed" to True */protected synchronized void setchanged () {changed = TRUE; }/** * Resets "changed" to False */protected synchronized void clearchanged () {changed = FALSE; }/** * Detects if this object has changed */public synchronized Boolean hasChanged () {return changed; }/** * Returns the number of observers of this This class represents an obse
Seven major design principles:1. Single Duty principle: one class is responsible for a duty.2, the Richter replacement principle: Subclasses can extend the function of the parent class, but cannot change the original function of the parent class.3, dependency inversion principle: The high-level module should not rely on the lower layer module, both should rely on its abstraction; abstraction should not depend on detail; detail should depend on abstrac
The design pattern (English pattern) is a solution to the recurring problems in object-oriented design. The term was introduced into computer science in the 1990 's by people such as Erich Gamma and others from the field of architectural design. The meaning of the term is also controversial. The algorithm is not a design
objects; The new object is used to re-use its existing functions by delegating methods that call existing objects. In short: Use the combination/aggregation relationship as much as possible, with less inheritance.7, Dimitri Law (least known principle) (Demeter Principle)Why is it called the least known principle, that is to say: an entity should be as small as possible interaction with other entities, so that the system function module is relatively independent. This means that a software entit
Six main principles:Single duty;Opening and closing principle;Dimitri Principle;The principle of the Richter replacement;dependency inversion principle;Interface Isolation principle23 Different design modes: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, e
copy behavior of the object, you should also override the Copywithzone: methodOverrides should ensure that no new objects are created, such as:-(ID) Copywithzone: (struct _nszone *) zone {return self}5) If memory management uses non-arc, also consider overriding the Retain methodIt is necessary to ensure that the single object release is destroyed once, and retain does not make any sense, such as:-(ID) retain{return self;}
Implementation of single-instance
, high-level modules and the underlying module should be dependent on abstraction.2, detail also relies on abstraction.4. The principle of substitution on the Richter scaleSubclasses can replace parent types.Only if the subclass can replace the parent class, the Software unit function is not affected, the parent class is actually reused, and the subclass can also be a new behavior on the basis of the parent class.Because of the substitution of subtypes, modules that use the parent class type can
Java Six Design Patterns1. Single responsibility Rule (SRP): There is only one reason for the change of class.2. Dependency inversion rule (DIP):1, the high-level module should not rely on the underlying module, both with the dependency interface;2, the interface does not depend on the details; 3, the detail depends on the interface.3. Interface isolation rules: dependencies between classes should be based on a minimum number of interfaces.4, the R
Opening and closing principle OCP (Open for extension,closed for modification). The core idea of open and close principle is that an object is opened to expansion and closed to modification.
In fact, the opening and closing principle means that changes to the class are made by adding code rather than altering the existing code. In other words, once the software developer writes out the code that can be run, it should not change it, but to ensure that it can continue to run, how to do this? Th
language is:1 , the dependencies between the modules can occur through abstraction, and the implementation class cannot have direct dependencies between them, and their dependencies are generated by interfaces or abstract classes;2 , interface, or abstract class does not depend on the implementation class;3 , implementing class-dependent interfaces or abstract classes;a more streamlined definition is "interface-oriented programming" ------OOD one of the essence. Benefits of the dependency inver
Command of design patterns-TV
Every night, TV remote control is a retained program in our house. My daughter prefers to watch cartoons, my wife prefers to watch TV series, and I prefer to watch football. Therefore, whoever controls the remote control is equal to realizing their own program dream. Hey, in fact, every time my daughter succeeded, and she said for a while, "Should you make the big one smal
Design principle one : single principle of responsibility Definition: There should be only one reason for a class to cause it to change. Advantages: Reduce the complexity of the class, improve the readability of the class, improve the maintainability of the system. Example: Super Human public class Superman {public void Maintains world peace () {//Superman maintains world Peace}} Extension: public class Animal {Public void Breathe (String animal) {Sys
Why design patterns? Let's take a look at the six principles and use the design pattern principles.
Introduction
I don't like reading books very much, because I forgot to read ten lines of books, so I read the left teacher and copied it to improve my memory.
This is the http://www.cnblogs.com/zuoxiaolong/p/pattern1.html of o
Design principles of design patterns (medium)Interface Segregation Principle, then multiple interfaces are used instead. Each interface serves only one submodule. This is similar to the single responsibility principle shared for the last time. Purpose of designing the interface isolation principle: when designing an application, if a module contains multiple sub-
The original * * * * may need to change the application, separate them (encapsulated), and do not mix with the code that does not need to change.
The original * * * for interface programming, rather than for implementation programming, here for interface programming really mean "for super type Supertype programming", the key is polymorphism.
The original * * * Multiple use combination, less with inheritance.
Mode * * * * Strategy mode (Strategy pattern): Defines the algorithm family (a group
Java Singleton design pattern, there are many ways to implement, the following describes some of the more famous implementation methods
A Hungry man typeThis design pattern is simple, and there is no multi-threading security problem, which is generally used in practical development.
Class Hungerydemo{private Hungerydemo () {}private static final Hungerydemo instance = new Hungerydemo ();p ubli
No nonsense C # One of the design patterns: the beginning
What is the design model?
What is Shaolin boxing? Shaolin Boxing is a set of martial arts routines that Shaolin monks have drawn after a long summary. There is a secret of Martial Arts called Shaolin Boxing, which records the applicable groups, style routines, and after-learning effects of this box
: Interface high cohesion is internally highly dependent and isolated as much as possible. That is, the method of internal declaration of an interface is related to a sub-module, and is required by this submodule.
Interface design is limited: If you fully follow the principle of interface separation, there will be a problem, that is, the design of the interface will be less and less, so that the number
}Singletonlazy The object is not created immediately after it is loaded into the method area, it is not created until the GetInstance method is called. This way can save memory space, but there is also a thread security problem, when thread a execution to the judgment object is null, when thread B gets execution, thread B determines that the object is null, then thread a regain execution, create the object, thread B resumes, continue to create the object. Modify the code as follows, using a sync
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.