{void吃饭();void看电影();void逛街();void啪啪啪();}abstractclass恋爱中的妹子 implements 谈恋爱{@Overridepublicvoid吃饭() {// TODO Auto-generated method stub}@Overridepublicvoid看电影() {// TODO Auto-generated method stub}@Overridepublicvoid逛街() {// TODO Auto-generated method stub}@Overridepublicvoid啪啪啪() {// TODO Auto-generated method stub}}class阿乐 extends 恋爱中的妹子{publicvoid啪啪啪() {// TODO Auto-generated method stubSystem.out.println("阿乐:亚美爹,好害羞");}}}
Here I have written an interface that defines several methods
deserializing.Ultimate single-Case mode F: Public class singletonf implements Serializable { Private Static class singletonholder { /** * Singleton object instance * / Static Finalsingletonf INSTANCE =NewSingletonf (); } Public StaticSingletonfgetinstance() {returnSingletonholder.instance; }/** * Private constructor is used to avoid external instantiation of objects directly using new */ Private singletonf() { }The /** * Readresolve method should be used when
implementation for all three of these methods. Therefore, any concrete class that inherits from the abstract class Serviceadapter can choose the method implementation that it needs, regardless of the other unwanted methods. the adapter mode is intended to change the interface of the source so that it is compatible with the target interface. The default adaptation is slightly different , and it is a mediocre implementation provided to facilitate the creation of a non-mediocre adapter class.At
coupling between classes, improve the stability of the system, reduce the risk caused by concurrent development, and improve the readability and maintainability of the code. Let's then use the example in the JDK to illustrate:Look at the following section of code:publicclass Test { publicstaticvoidmain(String[] args) { List list=new ArrayList(); list.add("11"); System.out.println(list.get(0)); }}This code we run is definitely output 11; Next we modify the codepubliccl
, each additional element class needs to modify the visitor Class (also includes the visitor class subclass or the implementation Class), the modification is quite troublesome. In other words, the visitor pattern should be used with caution in cases where the number of element classes is uncertain. Therefore, the visitor pattern is suitable for the reconstruction of the existing function, for example, the basic function of a project has been determined, the element class data has been basically
The last one mainly introduced several created design patterns Abstractfactroy,factorymethod and Singliton. Their common features are used to create objects. The next thing that comes up here is a couple of structural patterns. The so-called structural pattern is used to solve the process of creating a system structure by making a reasonable and effective combina
Hungry man mode and the lazy mode, and according to the implementation details of the specific project, we can apply the template code to the application of the singleton design pattern.Advantages of a singleton design patternFinally, let's summarize the advantages of a singleton design pattern: can be controlled access to unique instances; The ability to redu
construction methodPrivateSingletontest () {}Defines a static private variable (uninitialized, does not use the final keyword, and volatile guarantees the visibility of the instance variable when multi-threaded access is avoided, and is called by another thread when the other variable property is not assigned when instance initialized)Privatestatic volatile singletontest instance;//defines a common static method that returns an instance of this type public Span style= "COLOR: #0000ff" >static S
; } Public void setData (String data) { this. data = data; }} 5. The Observer object (Observer) "pull" the data to get the data response. The code is as follows: Public class Implements iobserver { @Override publicvoid refresh (Isubject obj) { // TODO auto-generated method stub Subject Subject = (Subject) obj; System.out.println ("Data is being updated to:" +Subject.getdata ());} }Finally, write a test class to test: Public class Test { public
, do not need to create factory objects, this pattern is more extensive, the code example is as follows: Package Com.factory.factorymethod;public class Senderfactory {public static sendable Producetextsender () { return New Textsender (); } public static sendable Producephotosender () { return to new Photosender ();} public static sendable Producevideosender ( { return new Videosender ();} } Factory Method Model Summary When there are a large number of products that need to be created and
First, IntroductionThe singleton mode is one of the Java23 design patterns, and the main function of the singleton mode is to ensure that only one instance of a class is present in a Java application.Second, the characteristicsThe singleton mode has the following characteristics:1, the Singleton class can have only one instance.2, the Singleton class must create
single-state design patterns in Java2011-09-23 16:38:46|Category: Java |Tags:technology! | Report | Font size Subscription This blog post is a blog post from a blogger called "Junny's Blog". Feel this blog is really good, so take it out here to share! (I just made a few changes to the code.)A concept:Design pattern: The
1. Strategy design modeCreating a method that can vary depending on the parameter object being passed is called a policy design pattern. This type of method contains a fixed portion of the algorithm that is requested to execute, and the "policy" contains the changed parts. A policy is a parameter object that is passed in. In the following code example, the process object is a policy. Applied on the S.code e
combination of objects, it is possible to mix and match the beverage and seasoning more flexibly.Code External details:When implemented in code, the decorator can be passed into the decorator by the constructor, as in the final invocation form as follows:Beverage beverage = new Darkroast ();Beverage = new Mocha (beverage);Beverage = new Whip (beverage);The two-tier wrapper is completed, and the cost () function of the beverage is then called to get the total price.Seven, java.io in the package
... ") ;}}; Class factory{//factory class public static Fruit Getfruit (String className) {Fruit F = null, if ("Apple". Equals (ClassName)) {f = new A Pple ();} if ("Orange". Equals (ClassName)) {f = new orange ();} return f;}; public class Interdemo{public static void Main (String args[]) {Fruit f = factory.getfruit (Args[0]); if (f!=null) {f.eat ();} }}Three, the agent design modeTake debt collection as an exampleInterface give{public void Givemone
Observer Observableex Public class extends Observable { /** * When the principal changes, the notification method is called @param newstate * /publicvoid change (String newstate) {this . Nodifyobservers (newstate); } }5. Create a clientImportorg.junit.Test; Public classClient {/*** Create three new observers, add them to the list, and call the change method*/@Test Public voidTest () {Observer OBS1=NewObserverimpl (); Observer OBS2=NewObserverimpl (); Observ
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.