桥梁模式

interface Implementor
{
	public void doSomething();
	public void doAnything();
}
class ConcreteImplementor1 implements Implementor
{
	public void doSomething()
	{
		
	}
	
	public void doAnything()
	{
		
	}
}

class ConcreteImplementor2 implements Implementor
{
	public void doSomething()
	{
		
	}
	
	public void doAnything()
	{
		
	}
}

 

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

 

class RefinedAbstraction extends Abstraction
{
	public RefinedAbstraction(Implementor _imp)
	{
		super(_imp);
	}
	
	@Override
	public void request()
	{
		super.request();
		super.getImp().doAnything();
	}
}

最后是main类

public class Client
{
	public static void main(String[] args)
	{
		Implementor imp = new ConcreteImplementor1();
		Abstraction abs = new RefinedAbstraction(imp);
		abs.request();
	}
}

 这种模式应该是个程序员都会使用,没有什么好说的,或者说都不能称为一种模式。

你可能感兴趣的:(桥梁模式)