of the current object */
Bytearrayoutputstream BOS = new Bytearrayoutputstream ();
ObjectOutputStream oos = new ObjectOutputStream (BOS);
Oos.writeobject (this);
/* read out the new object generated by the binary stream */
Bytearrayinputstream bis = new Bytearrayinputstream (Bos.tobytearray ());
ObjectInputStream ois = new ObjectInputStream (bis);
return Ois.readobject ();
}
Public String getString () {
return string;
}
public void SetString (string string) {
, filterinputstream,filteroutputstream
Concretedecorate Specific Decorative roles: responsible for adding new responsibilities to component objects, Bufferedinputstream,bufferedoutputstream, etc.
Advantages
Extended object functionality is more flexible than inheritance and does not result in a dramatic increase in the number of classes.
You can decorate an object multiple times, creating a combination of different behaviors and getting more powerful objects.
The concre
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 code, which is an action required by class i
Recently looking at design patterns a book, found that the strategy model and simple factory model is very much like, just beginning I thought it was the same, the total feel no difference, then see understand, have a little personal understanding, record down, convenient next review and understanding.
Concept Understanding: Polymorphism: C + + polymorphism In a nutshell is, in the base class of the function plus the virtual keyword, in a derived clas
expression match the premise of success, as little as possible matching, that is, the so-called "not greedy", popular point, is to find a want to pick up on the line, as to whether there is no not to pick up on the matter.2.1.2 on the prerequisitesIn the above analysis of greedy and non-greedy patterns from the application perspective, a prerequisite is always mentioned is "the whole expression matching success", why should we emphasize this premise,
The appearance pattern of design patterns in Python advocates less coupling with multiple modules for code management, and is illustrated with examples below.
Application Features:
When many complex and small functions need to invoke requirements, and these calls often have a certain relevance, that is, a call is a series of.
Structural characteristics:
The original complex and numerous calls, planning unified into an entry class, from this only thro
There are about 10 behavior patterns, which are divided into the upper, middle, and lower layers. 1. Template Description: defines the skeleton of some Operation algorithms and delays implementation to its subclass. Advantages: Strong scalability example: the Java Abstract class is originally the Template mode, therefore, it is widely used. it is easy to understand and use. Let's start with an example: public abstract class Benchmark {/***. The follow
Illustration: Java 23 design patterns Note 1, Java 23 Design PatternsIterator pattern 1.1 Iterator Pattern
The element code in the array arr is displayed in Java as follows:
1 for (int I = 0; I
Many elements are saved in the array. By specifying the array subscript, we can select any element from it.
In the for statement, I ++ is used to increase the I value by 1 after each loop, so that the next element, the next element, and the next element in
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 design
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 design
? In fact, you don't have to worry about where to put it. The dimit rule gives us a solution:
If a method is put in this class, that is, the relationship between classes is not added, and there is no negative impact on this class, it is placed in the class.
4. Attention to the dimit rule (iii) -- use serialization with caution
Serialization is used to sequence object memory data so that it can be transmitted through different media. However, if our software system model is c/s and the client
maintenance, or when a third-party library is used. Example code:
View code
// Unified Access to wages Public Interface Salery { String Getsalery ();} // The agent of the technical department, because the technical department does not have access to the company's salary, you need to set up an agent of the human resources department to get the salary Class Teckdepartmentproxy: salery { Private Hrdepartment AHR; Public String Getsalery (){ If (AHR =Null ) {AHR = N
The structure mode discusses the structure of classes and objects. It uses an Inheritance Mechanism to combine interfaces or implementations (class structure mode), or by combining some objects, to implement new functions (object structure mode ). In gof23, there are 7 structural patterns. The specific categories are as follows:
Adapter Mode
Convert an interface to another interface that the customer wants. The adapter mode allows the classes that
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.