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,
Highlights of design patterns (I) and highlights of design patterns
The main document of the design pattern is "big talk Design Pattern". In the first stage, we will first look at the basic concepts of various patterns to implement examples under each pattern. Then, you can learn and understand the benefits of various modes and know that a certain mode is suitabl
Learning JavaScript design patterns: singleton and javascript Design Patterns
I. Definition
Ensure that a class has only one instance and provides a global access point to it.When you click the login button, a login floating window appears on the page, which is unique. No matter how many login buttons are clicked, this floating window will only be created once, this login floating window is suitable for cre
32 design patterns and 32 Design Patterns
32 Design Patterns
Good stuff has to be transferredAfter reading this article on the Internet, the author uses a simple language to compare the 32 java models, which is very helpful.
Creation Mode
1. FACTORY-try to catch up with MM. The chicken wings of McDonald's and the chicken wings of KFC are what MM loves. Although t
The following 23 design patterns are mentioned in the design pattern book:Abstractfactory: Provides an interface to create a series of related or interdependent objects without specifying their specific classes.Adapter: Transforms the interface of a class into another interface that the customer wants. The adapter mode makes it possible for those classes that would otherwise not work together because of incompatible interfaces to work together.Bridge:
sentence may not be easy-to-understand. To put it bluntly, it means the conventional rule. You only need to clearly describe whether the corresponding occasion is really suitable)5. pattern is a means to record the software architecture. (The meaning of this sentence is to tell you which modes are used in this software architecture, and my colleagues have stipulated that your modifications or extensions must follow the general direction of the mode, the steps against these
com.roc.decorate; Public class extends fight{ @Override publicvoid boxing () { System.out.println (" Punch ");} } Packagecom.roc.decorate; Public classDscribefightextendstruefight{/*** You can't say it's a direct call, to describe, to describe*/ Private voidsay () {System.out.println ("Auntie, I'm having a game with xiaoming."); } Public voidBoxing () { This. Say (); Super. boxing (); System.out.println ("Great place to stay"); }} Package com.roc.decorate;
To tell the truth, the feeling is not very much, may not encounter too many scenes,So there's no sense in the application scenario.Anyway, all kinds of patterns are the instances of the class passed, over time, produced some rules ... :)#The wheels, the engines, the bodies, the definitions, they don't have to change.classWheel:def __init__(self, name): Self.name=namedefAccept (self, visitor):#each visitor is the same, but the method is different, for
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
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.