observer;/** * Specific observer classes, such as LV Zeng in the example, Zhang Wei is an example of the Observer * @author WL * */public class Concretewatcher implements watcher { String Watcheredname; String Name;public concretewatcher (String name,string watcheredname) {this.name=name;this.watcheredname= Watcheredname;} @Overridepublic void Updata (String str) {System.out.println (name+ "Heart secretly happy" Hey!!! The opportunity came, my "+watcheredname+" said she ' "+str+" ' "");}Package
);/** * update Price */ Food.setprice (1.5f);}}third, the application scenarioGUI frame, meteorological observation, etc.Iv. SummaryBe sure to call the Setchanged () method before notifying all observers to set the state of the observer to be changed so that notifyobservers () will not be updated with the Observer Update method. If there are different opinions or omissions in the above content, please give us some valuable suggestions or comments.Finally, you can try to use the following UML mod
();
}
}
}
public class Mysubject extends Abstractsubject {
@Override
public void operation () {
System.out.println ("Update self!");
Notifyobservers ();
}
}
Test class:
public class Observertest {
public static void Main (string[] args) {
Subject sub = new Mysubject ();
Sub.add (New Observer1 ());
Sub.add (New Observer2 ());
Sub.operation ();
}
}
Output:Update self!Observer1 has rece
There are many similarities between structural patterns because there are several relationships in the object model structure: inheritance and implementation between classes, plus object combinations, which are the main purposes of the PHP design pattern.
The greatest advantage of the combination of objects is that you can build a relationship based on configuration at run time without modifying the actual
relatively single; when we find that a class takes on too many tasks, Too miscellaneous should assign some responsibilities to other classes, so as to guarantee the high cohesion of the design scheme
Controller mode: The controller mode requires that the coordinate processing system messages be assigned to different control classes
Polymorphism: When a duty behaves differently in different derived classes, we can use polymorphic
object is often subject to drastic changes, however, the algorithms that combine sub-objects in each part are relatively stable. To put it simply, sub-objects change frequently and are relatively stable for the combined sub-object algorithm.This is a solution to the creation of a complex object. The changed part and the relatively stable part have been clarified. What we need to do is to isolate the change and how to isolate the sub-objects from the algorithm is a problem to be solved.In
Bridge)The bridge mode is used to solve the problem of multi-dimensional changes of the system. It separates the abstract part from the implementation part so that they can all change independently. (See the understanding of the Bridge Mode)Structure:Examples in life:
Composite)
Intent:Combine objects into a tree structure to represent the "part-whole" hierarchy. The composite mode ensures consistency between the use of a single object and a composite object. [Gof
Looking at "C + + Design new thinking", found in the beginning of a large length of the introduction of the Strategy Model (policy), the strategy model is not a classic design pattern, but in fact, in our day-to-day development is essential. Policy, strategy, policy, the meaning here is that the complex function of the class as far as possible to split into a single function of a simple class combination, s
like this, it is indeed too complicated. However, the actual problems are often not so simple and there will be many additional requirements. For example, if all objects have the initialize method, you must ensure that the initialize method is called for normal initialization during object creation, for example, we may need to add additional logic judgment when creating ConcreteObjectA, etc. Different object creation and initialization processes will follow. Based on the above implementation, w
I. Overview of the pattern
The Strategy mode (strategy pattern) is similar in shape to the state mode, but somewhat different in intent. The intention is to make these algorithms interchangeable and provide a way to select the most appropriate algorithm.
In my application of OOP design process Evolution (iii) This article applies to the Strategy model, in the book's rent calculation on a variety of situations, each type of book rental is not the sam
What is the design pattern?Design patterns are a set of reusable, most known, categorized purposes, code design experience Summary. Design patterns are used to reuse code, make code easier for others to understand, and ensure code
Design patterns are one of the best ways to share design ideas. Design patterns provide software architects and designers with the tools or languages they need to solve recurring problems in a systematic way to gain some experience. This series includes two sections that dis
Public key system and distributed environment requirements
Vision Wang)
2009-02-10 Summary
As a continuation of the first version of "Design Patterns-engineering implementation and expansion based on C #", we plan to launch the security design patterns series and integration pattern series) data pattern, data acce
class creation mode, also called the Static Factory method (Factory) mode
8. Example explains the simple Factory mode in PHP design mode programming, the example explains the design pattern
Introduction: The example explains the simple factory pattern in PHP design pattern programming, the example explains the design
Design principles (7 types): There are so many principles that guide us in the design and development of our programs because there is an unknown change in our program. In order to embrace this unknown change at the lowest cost, our predecessors summed up so many principles. ① Yagni PrinciplesYou aren ' t gonna need itDo not write code that you do not need②kiss PrinciplesKeep it simple and stupidCode keepin
This article is for translating articlesOriginal address: Design Patterns in PHPIf you intend to learn PHP children's shoes can refer to the author's programming language learning Knowledge system Essentials ListThis article mainly discusses in the web development, is accurate, is the PHP development the related design pattern and the application. Experienced dev
As the first article in this series, I would like to express my personal understanding of design patterns. So I ask myself to answer a few questions. 1, what is design mode? 2, is the design pattern important today in the fast software iteration? 3, Gang of four proposed 23 design
The 23 design Patterns in Gof design patterns can be divided into three groups: Creation (creational), structural (Structural), behavioral (behavioral). Below to do a detailed analysis.Create typeCreate pattern processing object constructs and references. They abstracted the instantiation responsibility of the object i
Ref http://industriallogic.com/papers/learning.html#STUDY
Design Patterns navigation
LFactory methodSession 1
BeginFactory method. This pattern is used by a number of patterns in the book and throughout the patterns literature.
UStrategySession 2
StrategyIs used frequently throughout the book, and an
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.