changes of the person being observed4. The actual observer classConcretobserver inherits Observer interface, implements update ()Observer instance:Publicinterfacestudentsubject{publicvoidaddobserver (ParentObserverone); Publicvoidmoveobserver (Parentobserverone);p ublicvoidnotifyobserver ();} packagesuperhakcetoolspackage;importjava.util.arraylist;publicclassstudent Implementsstudentsubject{privatefloatgrades;privatearraylistThis article is from the "Superhakce" blog, make sure to keep this sou
= "Http://img.my.csdn.net/uploads/201309/01/1378037235_7476.jpg"=new Webpimageloader (); Loader.downloadimage (IMAGEURL,200,200);Pattern mode Advantages and disadvantages: 1.) Advantages The template method pattern removes duplicate code from subclasses by moving the invariant behavior to the superclass. Subclasses implement some of the details of the algorithm, which facilitates the expansion of the algorithm.By invoking the subclass implementation of a parent class, the new behavior is adde
Userwang=NewUser ("Wangwu"); Server.registerobserver (Userzhang); Server.registerobserver (Userli); Server.registerobserver (Userwang); Server.setinfomation ("PHP is the best language in the world!" "); System.out.println ("----------------------------------------------"); Server.removeobserver (Userzhang); Server.setinfomation ("Java is the best language in the world!" "); }}Test results:6. Summary
This pattern i
");/** The problem is: Zhao Yun actually do not know is that strategy ah, he only know to dismantle the first bag,* And do not know is backdoor this ingenious idea, how to do? It seems that this strategy model has already written out the name of the stratagem.*Wrong Backdoor, Givengreenlight, Blockenemy is just a code, you write first, second,Third, no one will say you're wrong!** The advantage of the strategy model is that it embodies the characteristics of cohesion-poly-low coupling, the disad
JAVA design patterns-Singleton and singletonReprinted please indicate the source: http://blog.csdn.net/l1028386804/article/details/45441169I,Overview
Ensure that a class has only one instance and provides a global access point to it.II,
Applicability
1. When the class can only have one instance and the customer can access it from a well-known access point.
2. Whe
Jobseeker ("Mike"));
Hh.registerobserver (New Jobseeker ("Chris"));
Hh.registerobserver (New Jobseeker ("Jeff"));
Every time you add a job, all job-seeking people are notified.
hh.addjob ("Google Job");
Hh.addjob ("Yahoo Job");
}
The advantages of the Observer pattern The Observer and the observed are mildly correlated and abstract coupled so that It's easier for both to expand. The Observer pattern is a commonly used trigger mechanism that forms a chain o
JAVA design patterns ---------- Proxy)
Here is a brief introduction to the use of the most basic proxy.
Agency: Simply put, one person or one institution takes action on behalf of another person or another institution. In some cases, a customer does not want or cannot directly reference an object, but the proxy object can play a mediation role before the client a
The disadvantage of creating an object with the New keyword is that the coupling is too high, and the factory design pattern uses the Java reflection mechanism to instantiate the object to reduce the degree of couplingPackageCn.buaa;Importjava.util.Date;Interfacefruit{ Public voideat ();}classAppleImplementsfruit{@Override Public voideat () {System.out.println ("Eat apples"); }}classOrangeImplementsfruit{@O
PackageShipeiqidemo;/** A common design pattern in Java: Adapter * Source: A subclass to implement the interface, then you have to implement the interface of all the abstract methods, sometimes the abstract method * a lot, but do not need to implement all, so at this time define an abstract class to implement this interface, and then through the subclass to inherit * In this abstract class, this abstract cl
Basic Principles of java Design Patterns
Two principles have been introduced earlier.Open and closed PrincipleSingle Responsibility PrincipleLet's take a look at another principle: the Dependency inversion principle, which includes two aspects:A. High-level modules should not depend on low-level modules. They should all rely on abstraction.B. abstraction should n
class Sendmailfactory implements Provider {
@Override
Public Sender Produce () {
return new MailSender ();
}
}
public class Sendsmsfactory implements provider{
@Override
Public Sender Produce () {
return new Smssender ();
}
}
In providing an interface:
Public interface Provider {
Public Sender produce ();
}
Test class:
public class Test {
public static void Main (string[] args) {
Pr
A singleton pattern (Singleton pattern) is a very common design pattern. The core is to ensure that there is only one instance of the Singleton class in the system. There are a number of situations in the system that involve configuration data and the generation of unique sequence IDs.Refer to the definition of "Zen in design mode":Ensure a class have only one instance,and provide a global point of access t
passed in, that is to show Likeeat likeeat = new Endeat (New Eatfoot (New Inrestaurant (New Gotorestaurant (New Findinmap (person)))))The look of this structure. So when calling Likeeat.eat () , and because of each specific decorator class, first call super.eat (); method, and the Super has been passed by the construction and pointed to a specific decorator class (this can be replaced according to the order), then called the Decoration class method, and then call their own decorative m
value:A.ceshi1 ();B.ceshi2 ();}}Test the function of a single caseClass a{int num1;Test passed a single-case pass valuepublic void Ceshi1 () {SingleInstance1 S1 = singleinstance1.getinstance (); s1.num = NUM1;//pass NUM1 to Num}}Class b{int num2;Assigning values by passing parameterspublic void Test (a a) {num2 = A.NUM1;}Test passed a single-case pass valuepublic void Ceshi2 () {SingleInstance1 s2 = singleinstance1.getinstance (); num2 = s2.num;//Pass num to num2}}Article original, re
JavaWhat are the common design patterns? Describes the Factory mode. Total at species, divided into three categories: creation, structural, behavioralI only remember the usual ones. 6 , 7 species, respectively:Created (Factory, factory method, abstract factory, Singleton)Structural type (packaging, adaptors, combinations, proxies)Behavior (Viewer, template, strategy)then talk about your understanding of th
{public double createoperation (double Numbera, Double numberb,string oper);}2, create a function of the implementation of the interface, we put this subtraction algorithm is written in this implementation class, the class can be loaded when the initialization, this way, you need to use the direct call./** * Created by LK on 2016/5/8. */public class Operationfunction {private static mapNow, the difference with non-functional is that we don't need to create a lot of implementations and create
the agent { SYSTEM.OUT.PRINTLN ("Business logic output------------completed before--------------Agent");} Custom method: The agent finishes after the logical private void Postrequest () {System.out.println ("--------------the agent completes the business logic output-------------");} Main method public static void main (string[] args) {Proxysubject proxysubject = new Proxysubject ();p roxysubject.request ();}} Copyright NOTICE: This article for Bo Master original article, without Bo Master perm
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.