现在的位置: 首页 > 综合 > 正文

桥接模式

2013年11月06日 ⁄ 综合 ⁄ 共 687字 ⁄ 字号 评论关闭

1.桥接模式的定义

将抽象部分实现与抽象分离,使其他们能独立的变化

2.桥接模式的UML

3.代码实现

public interface Implementor
{
	public void operationImpl();
}

public class ConcreteImplementB implements Implementor
{
	public void operationImpl(){
	
	}
}

public class ConcreteImplementA implements Implementor
{
	public void operationImpl(){
	
	}
}

public abstract class Abstraction{
	protected Implementor impl;
	public Abstraction(Implementor impl){
	   this.impl=impl;
	}
	public  void operation(){
		this.impl.operationImpl();
	}
}

public class RefinedAbstraction extends Abstraction
{
	public  void operation(){
		this.impl.operationImpl();
	}
}

public class Client
{
	public static void main(String[] args){
	    Implementor impl=new ConcreteImplementB();
        Abstraction asb=new RefinedAbstraction(impl);
		asb.operation();
	}
}

3.桥接模式的本质:分离抽象与实现。

抱歉!评论已关闭.