Category:
After learning about such a multi-mode model, many behavior patterns have also been designed during the learning process. What are the behavior patterns? One by one.
Iterator Mode
Http://blog.csdn.net/huo065000/article/details/24352437
Intermediary Mode
Http://blog.csdn.net/huo065000/article/details/22856883
Memorandum Mode
Http://blog.csdn.net/huo065000/articl
= 100.0f; Private floatdiameter = 10.0f; /*** Growth behavior, each call length and radius increase by one times*/ Public voidgrow () { This. diameter *= 2; This. Height *= 2; } /*** Reduce the behavior by half the length and radius of each call*/ Public voidshrink () { This. diameter/= 2; This. Height/= 2; }}View CodeClient class: Packageprototype;Importjava.util.Date; Public classClient {PrivateMonkey Monkey =NewMonkey (NewDate (),NewGoldringedstaff ()); Public voidChange () {//
Design Patterns-understanding of appearance patterns
Appearance mode: provides a consistent interface for a group of interfaces in the subsystem. This mode defines a high-level interface, making the subsystem easier to use.
In the data room charging system, the appearance mode is used to remove the coupling between the U layer and the B layer. According to the pr
on request: Anyone who has used a servlet knows that, in addition to having a corresponding configuration in Web. xml, it is necessary to inherit an abstract class called httpservlet, and rewrite the Doget and Dopost methods (and, of course, just rewrite the service method).Many of the methods in the request object are used when the internal components interact with each other, such as setcomet, setrequestedsessionid, etc. (not listed here). These methods are not exposed externally, but must b
Php design patterns-Abstract factory patterns
Provides an interface for creating a set of related or interdependent objects without specifying their specific classes.
Features
Abstract Factory is a common software design model that provides a unified creation interface for a product family. When you need a seri
) {objectstructure o=new objectstructure (); Attach (New Concreteelementa ()); O. Attach (New Concreteelementb ()); ConcreteVisitor1 v1=new ConcreteVisitor1 (); ConcreteVisitor2 v2=new ConcreteVisitor2 (); O.accept (v1); O. Accept (v2);//If the newly added operation is//concretevisitor3 v3=new ConcreteVisitor3 () as the following code; O.accept (v3);}Okay, now think about what time we use this model? In general, when the data structure is relatively stable, we use this pattern to encode, t
. the difference between equals and = = Earlier we saw that both the Clone object and the equals and = = of the original object return false, whether it is a shallow copy or a deep copy. So what is the relationship between equals and = =? For basic data types, = = compares their values. For non-primitive types of objects, = = comparison is their address in memory, such as the previous oldobject and newobject the same address, while the Equals method, if it does not overwrite the quilt class, it
void Decrator (person component) {this.component = component; public override void Show () {if (component!=null) {component. Show (); }}}///base. Show ();}} class Jonson:finery {public override void Show () {Console.WriteLine ("Jeans"); Base. Show (); }} class Shose:finery {public override void Show () {Console.WriteLine ("Bull Shoes"); Base. Show (); } }}* Each functional layer is loaded together, then the inner function is called by the topmost instance
is the new Pegadapter, called Two-way adapter:1 Public classPegadapterImplementsiroundpeg,isquarepeg{2 3 Privateroundpeg roundpeg;4 Privatesquarepeg squarepeg;5 6 //Construction Method7 PublicPegadapter (Roundpeg peg) { This. roundpeg=peg;}8 //Construction Method9 PublicPegadapter (Squarepeg Peg) ( This. squarepeg=peg;)Ten One Public voidInsert (String str) {roundpeg.insertintohole (str);} A -} There is also a kind of called pluggable adapters, can dynamically
observers, that is, dependent objects, each time data changes, these 2 view will changeclassHexviewer (object):defUpdate (self, subject):Print 'hexviewer:subject%s has data 0x%x'%(Subject.name, Subject.data)classDecimalviewer (object):defUpdate (self, subject):Print 'decimalviewer:subject%s has data%d'%(Subject.name, Subject.data)if __name__=='__main__': Data1= Data ('Data 1') Data2= Data ('Data 2') View1=decimalviewer () view2=hexviewer () Data1.attach (view1) Data1.attach (view2) Data2.attach
Java classic 23 design patterns: behavioral patterns (4)
This article describes the policy mode, template method, and visitor mode in 11 behavioral design patterns.I. Policy Mode
Define a series of algorithms, encapsulate each of them, and make them replaceable. This mode allows algorithms to change independently of cu
Java implementation of structural design patterns-appearance patterns
I. Description
The appearance mode is also called the facade mode, which is to package a complex system. The external interfaces of the system are provided by the appearance class. When a complex system needs to provide external interfaces, it needs to encapsulate the interfaces provided extern
20170312: The reason for learning is that companies use Sprint.net, managed methods, prevent multiple instances of classes, waste space. NET Design Patterns:NET design Pattern Example Singleton pattern (Singleton pattern)One: Introduction to the Singleton mode: (Brief Introduction)Singleton mode (Singleton pattern), which guarantees that a class has only one instance, and provides a global access point to a
I. Introduction to the Model
Appearance patterns (façade pattern) can wrap a series of complex classes into a simple, closed interface. Also called the façade mode.
Second, the mode of intent
Each design pattern has its purpose, and we look at how the design patterns of the patriarch say it. According to Gof, the fa
parametric construct, generates an object A through the new keyword, and then produces a new object T by A.clone (), then the constructor is not used when the object is copied. Be executed. That is, only one construction method is executed during the copy process.Clone vs final two pair of enemies. The object's clone is caused by a conflict with the final property within the object. In the programmer class above, modify to private final address address; Remove Get,set method, proto.address= (Ad
(); Ocar.excet (); }}Template method Pattern Applicable scenario
One-time implementation of an invariant part of the algorithm, and the variable behavior is left to subclass to achieve.
The public behavior in each subclass should be extracted and centralized into a common parent class to avoid code duplication. This is a good example of what Opdyke and Johnson described as "re-factoring to generalize." First identify the differences in the existing code and separate the differen
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.