设计 模式

 

重构改善既有代码设计

https://www.cnblogs.com/pony1223/p/7530465.html

结构型模式

wrapper包装模式     -   adapter decorator

adapter适配器模式 wrapper包装器

public class Adapter extends Adaptee implements Target{
	
	//request接口方法     Adaptee 类的doSomething方法
	public void request(){
		super.doSomething();
	}
	
}

  

facade外观模式

composite组合模式

public class Composite extends Component{
	private List<Component> components = new ArrayList<>();
	
	public void add(Component component){
		components.add(component);
	}
	
	public List<Component> getChildren(){
		return this.components;
	}
}

  

  

decorator装饰模式

public abstract class Decorator extends Component{
	private Component component =null;
	private Decorator(Component _component){
		this.component=_component;
	}
	
	public void operate(){
		this.component.operate();
	}
}
public ConcreteDecorator extends Decorator{
	public ConcreteDecorator(Component _component){
		super(_component)
	}
	
	private method(){
		...
	}
	
	public void operate(){
		this.method();
		super.operate();
	}
}

  

 

bridge桥接模式  品牌手机运行软件 山寨工厂生产产品    抽像类调用实现类(可变化)  通过直接下载、发送邮件不同形式备份不同格式(pdf,word,excel)的文件  在不同操作系统平台(如Windows、Linux、Unix等)上播放多种格式的视频文件

public abstract class Abstract{
	private Implementor imp;
	private Abstract(Implementor _imp){
		this.imp=_imp;
	}
	
	public void request(){
		this.imp.doSomething();
	}
}

  

proxy代理模式

class Proxy:Subject{
	RealSubject realSubject;
	public override void Request(){
		if(realSubject==null){
			realSubject = new RealSubject();
			//realSubject = new RealSubject(this);
		}
		realSubject.Request();
	}
}

  

  

flyweight享元模式

 

 

 

 

 

 

 

 

 

行为模式

 

状态模式

public class ConcreteState :State{
	public void handle(Context context){
		...
		context.setState(new ConcreteState());
		context.request();
	}
}

public class Context{
	privats State state;
	
	public void setState(State state){
		this.state = state;
	}
	
	public void request(){
		this.state.handle(this);
	}
}

  

  访问者模式

public class Visitor:IVisitor{

	@override
	public void visit(ConcreteElement ele){
		//读取ele数据
	}
}

public class ConcreteElement:Element{

	...
	
	@override
	public void accept(IVisitor visitor){
		visitor.visit(this);
	}
}

  

 

观察者模式

public abstract class Subject{
	
	private Vector<Observer> observers = new Vector<Observer>();
	
	public void add(Observer o){
		this.observers.add(o);
	}
	public void del(Observer o){
		this.observers.remove(o);
	}

	public void notifyObservers(){
		for(Observer o:observers){
			o.update();
		}
	}
}

  

 责任链模式

public abstract class Handler{
	private Handler nextHandler;
	
	public final Response handlerMessage(Request request){
		Response response=null;
		if(this.getHandlerLevel().equals(request.getRequestLevel()){
			response= this.echo(request);
		}else{
			if(this.nextHandler!=null)			{
				response = this.nextHandler.handlerMessage(request);
			}else{
			
			}
		}
	}
	public void setNext(Handler handler){
		this.nextHandler = handler;	
	}
	
	protected abstract Level getHandlerLevel();
	protected abstract Response echo(Request request); }

  

结构型:


适配器

外观

装饰

桥接

组合

代理

享元

 

 

 

行为型:

责任链

命令

中介

 

 

观察者

策略

状态

访问

模板

 

 

 

 

 

https://www.cnblogs.com/antball/p/7650973.html

 

https://blog.csdn.net/zxc123e/article/details/71837923
http://plantuml.com/zh/class-diagram

桥接
https://www.cnblogs.com/betterboyz/p/9361784.html
https://www.cnblogs.com/pony1223/p/7530721.html
https://www.jianshu.com/p/ba06176b7399
https://www.jianshu.com/p/0daf3fd14804
http://c.biancheng.net/view/1364.html
https://design-patterns.readthedocs.io/zh_CN/latest/structural_patterns/bridge.html

https://www.cnblogs.com/laotiebuhuang/p/11194015.html
https://blog.csdn.net/m0_37907835/article/details/79680444
https://blog.csdn.net/jialinqiang/article/details/8882993
https://blog.csdn.net/jialinqiang/article/details/8871327
https://blog.csdn.net/jialinqiang/article/details/8886567
https://blog.csdn.net/jialinqiang/article/details/8869352
https://blog.csdn.net/jialinqiang/article/details/8869044

 

posted @ 2019-07-23 15:36  antball  阅读(140)  评论(0编辑  收藏  举报