您现在的位置是:网站首页> 设计模式 设计模式

桥接模式

夜雨 2015-10-21 17:08 设计模式,桥接模式 1588人已围观

简介桥接模式

public class Abstraction {
	
	protected Implementor implementor;
	
	public void SetImplementor(Implementor implementor){
		this.implementor=implementor;
	}
	
	public void Operation(){
		implementor.Operation();
	}

}


public abstract class Implementor {
	public abstract void Operation();

}


public class RefinedAbstraction extends Abstraction {

	@Override
	public void Operation() {
		// TODO Auto-generated method stub
		implementor.Operation();
	}

}


public class ConcreteImplementorA extends Implementor {

	@Override
	public void Operation() {
		// TODO Auto-generated method stub
		System.out.println("The concrete operation of classA");

	}

}


public class ConcreteImplementorB extends Implementor {

	@Override
	public void Operation() {
		// TODO Auto-generated method stub
		System.out.println("The concrete operation of classB");

	}

}


public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Abstraction abstraction=new RefinedAbstraction();
		
		abstraction.SetImplementor(new ConcreteImplementorA());
		abstraction.Operation();
		
		abstraction.SetImplementor(new ConcreteImplementorB());
		abstraction.Operation();

	}

}

很赞哦!(495)

上一篇: 没有了

下一篇:原型模式

文章评论

夜雨

夜雨(共34篇文章)

弃我去者,昨日之日不可留
乱我心者,今日之日多烦忧
长风万里送秋雁,对此可以酣高楼
蓬莱文章建安骨,中间小谢又清发
俱怀逸兴壮思飞,欲上青天览明月
抽刀断水水更流,举杯消愁愁更愁
人生在世不称意,明朝散发弄扁舟