Select Page

Bridge

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(); } 

About The Author

Cédric Walter

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.

Categories