Support

Forums

Contact Me

Bridge

Decouple an abstraction from its implementation so that the two can vary independently.

from the gang of the four





Source Code

/**
 * Defines Abstraction interface. Stores reference to implementation.
 * 
 * @role __Abstraction
 */
public abstract class Abstraction {
	/** Reference to actual implementation */
	private Implementor impl;

	/**
	 * @return implementation-in-action.
	 */
	protected Implementor getImplementor() {
		return impl;
	}

	/**
	 * This sample operation delegates call to particular implementation
	 */
	public void someOperation() {
		getImplementor().someOperationImpl();
	}
}

/**
 * Concrete implementation
 */

public class ConcreteImplementorA extends Implementor {
	/** @see patterns.gof.bridge.Implementor#someOperationImpl() */
	public void someOperationImpl() {
		// provide implementation here
	}
}

/**
 * Concrete implementation
 */

public class ConcreteImplementorB extends Implementor {
	/** @see patterns.gof.bridge.Implementor#someOperationImpl() */
	public void someOperationImpl() {
		// provide implementation here
	}
}

/**
 * Defines interface for implementation classes. Is not oblidged to provide
 * one-to-one correspondence to interface of Abstraction.
 * 
 * @role __Implementor
 */

public abstract class Implementor {
	/** Implement this method to provide implementation-specific behavior */
	public abstract void someOperationImpl();
}
You might also like:
Proxy
3041 days ago
Proxy
Provide a surrogate or placeholder for another object to control access to it. Options are provided
Flyweight
3041 days ago
Flyweight
Use sharing to support large numbers of fine-grained objects efficiently.Source Code/** * Declares
Adapter
3041 days ago
Adapter
Convert the interface of a class into another interface clients expect. Adapter lets classes work to
Decorator
3041 days ago
Decorator
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternati
blog comments powered by Disqus

Donations

Thank You for supporting my work