2012年3月26日星期一

UGG BootsSimple factory patternwill all need to instantiate the object respective into categori

Simple factory patternwill all need to instantiate the object respective into categories ,and then use the simple factory class to instantiate them .This reduces the coupling between classes ,easy to add and modify the program .
Need to add function words as long as add object class .The calculator for example ,operator is the variable part ,each operator into separate categories, so adding operator only needs to add a class can, for other types of no effect .
With the open closed principle .The factory method pattern and simple factory method # & 20284 ;but here ,each operator of the instantiation process is placed in a class, the class factory decomposition .
Simple factory pattern, we add an operator would need to add an operator in a factory class and add a corresponding case .This means that we changed the simple factory class .Not fully compliant with the open closed principle .
The factory method pattern, to add an operator ,plus an operator and a instantiate the class factory ,just add a class ,in full compliance with the open closed principle .The abstract factory pattern, abstract factory pattern is for the same category has different situation,Moncler Jackets, such as a database can be divided into SQL Access .
And the specific application and sqluser.accessuser.sqldepartment.accessdepartment. Then if a factory method would need four factories .If more so it is difficult to handle ,for sqluser and sqldepartment are SQL type can use an abstract factory to produce them both .
For accessuser and accessdepartment can use abstract access factory to produce .Figure 1 the equivalent of SQL factory A1 factory is equivalent to sqlUser .B1 is equivalent to sqldepartment.
The builder pattern about the construction of a complex object with his said separation ,makes the same construction which can create different representations .Di rector builder builder command ,to control the construction of the object .
ConcreteBuilder Builder .The parameter to the concreteBuilder method different can build different instance .Using builder ,his class in the construction method must be general enough ,for various types of concrete builder structure .
The construction process is stable ,such as people ,have to build head body arm leg. But these to build specific things different .Then use the builder pattern can make the construction of code and code separation ( specific construction code is in the concreteBuilder ,and control the construction of the Director is not aware of it .
If you need to change a product ,as long as the definition of a specific builder can! ) The prototype model is first built a prototype ,Cheap Beats By Dre,then let the specific class to inherit this prototype .
Use the clone method to clone the prototype .Pulic override Prototype Clone ( ) {Return ( Prototype ) this.memberwiseClone ( ) } so that we can achieve a simple clone .Note that there is a shallow copy .
Method of creating a new object ,UGG Boots,then the objects of non static fields are copied to the new object .If the field is & # 20540 ;type ,of the field is bitwise copy .If it is a reference type ,then the copy reference without copying the referenced object ;thus the original object and its copies refer to the same object .
( if it is a reference type ,create new objects are referenced to the object ,means at execution time ,the new object back to find him by pointing to the object ,the object is now what is what ,cloning .
While & # 20540 ;type is different ,it is a copy ,5 Fingers Shoes,cloned object & # 20540 ;gave the new object ,when the execution of the new object in the implementation ) is a deep copy :I understand :the original shallow copy just gave a new object of an address ,and the copy is the realization of the clone method ,the original object & # 20540 ;assigned to the new object .
This address to & # 20540 ;!The singleton pattern to ensure a class only has one instance .Let the class itself to preserve its unique instance ,when need to instantiate it just call ,whether is instantiated by the class of their own judgment .
Will instantiate the object stored in static variables, then can be instantiated and get it .It should be noted ,multiple threads to single patients .The use of Lock ( syncRoot ) lock ,Monster Headphones,this program allows only one thread to enter .
Related articles:

没有评论:

发表评论