Read about java design patterns interview questions, The latest news, videos, and discussion topics about java design patterns interview questions from alibabacloud.com
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) {
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 al
Common Java design patterns-adapter patterns
The Adapter mode is introduced to solve the incompatibility mismatch problem.
Definition:
The adapter mode converts the excuse of a class into another interface that the customer expects, so that the classes that originally cannot work together due to interface incompatibili
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
public Engine createEngine() { return new EngineB(); } @Override public Aircondition createAircondition() { return new AirconditionB(); } }Customer:[Java] View plain copy print? On code to view a snippet derived from my Code slicepublic class Customer {public static void Main (string[] args) {Production of BMW 320 series AccessoriesFactoryBMW320 factoryBMW320 = new FactoryBMW320 ();Factorybmw320.createengine ();Facto
Chapter 1 of design patterns-Abstract Factory patterns (Java implementation)"The last time was my fault. The author of bribery asked me to talk about it first. However, my wife and adults have a lot to do with me, this time, let me add the application scenarios that have not been completed last time." (After that, I to
Chapter 1 of design patterns-factory method patterns (Java implementation)"I come first", "No, husband, I come first !". I heard a few people from far away. Oh no, it's the factory method model and the abstract factory model. The couple are quarreling. nimei is not eating, not all come first (the world of food ~). "Abs
Structure mode, a total of seven kinds: Adapter mode, adorner mode, proxy mode, appearance mode, bridging mode, combined mode, enjoy the meta-mode.First, the adapter mode:The adapter pattern transforms the interface of a class into another interface that the client expects, in order to eliminate compatibility issues with classes caused by mismatched interfaces. There are three main categories: The adapter mode of the class, the adapter mode of the object, and the adapter mode of the interface. F
As the name implies, multiple cases are compared to a singleton pattern, which can have more than one finite instance, such as the following, can only have two instances.Import java.util.ArrayList;Import Java.util.Random;Class Multition{Private final static int max_number=2;private static arraylistprivate static int index=0;Private String Currentmultitioninfo;Static{for (int i=0;i{Index=i;Amultitionarraylist.add (New Multition ());}}Private Multition (){Currentmultitioninfo= "The current object
(); 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
, 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
create threads, how to create threads better (such as inheriting the thread class or calling the Runnable interface), and then gradually ask about concurrency problems like the Java memory model encountered in the process of Java concurrent programming, JDK1.5 introduces higher-order concurrency tools, common design patterns
adapter pattern?
Ø database How are you usually optimized, what other tools are used to optimize no, how to use the
Ø Now there is a lot of tables to correlate the query SQL, the child table data is very much, then you only from the SQL point of view of the SQL statement optimization, do not need to consider the index, predicate
Ø you don't have a Java project, do you?
Ø your major is to control the direction, why do the current direction
O you have
they do not follow good things. If you are lucky enough to have a R D team for DDD, agile, and XP, You can regard the project as a lifelong work of art. [Wang qingpei has all rights reserved. For more information, please sign it.]
These two articles are my thoughts on DDD and I will share them with you.
In the next article, we will share with you the detailed use of a small system with a DDD architecture as a case.Analysis and Modeling, use of design
Create bean Factory all useFactory methodFor the production of fixed products in the same grade structure support to increase any productAbstract FactoryAll products for the production of different product familiesAbstract product family can be added to the inability of the productPrototype mode (copy, clone)You need to implement the Cloneable interface using the Clone () method to copy a close () method such as a file streamCreating an object with new requires very tedious data preparation or
implementation is packaged into a class, if there are many alternative strategies, then the number of these classes is very large.To recognize a policy pattern from a code perspective:(Zhao Yun with three tricks to solve the problem, there are three elements in this scene: Three ingenious tricks, one capsule, one Zhao Yun)1. First create a policy interface (contains an algorithm that can be executed by each of the tips)2. Then write three implementation classes, because there are three clever t
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
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.