Select Page

Adapter

Adapter

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

Source Code

/**  * Defines an existing interface that needs adapting  *   * @role __Adaptee  */ public class Adaptee { 	/* Some adaptee-specific behavior */ 	public void specificRequest() { 		// some adaptee specific stuff is going here 	} }  /**  * This class adapts the interface of Adaptee to the Target interface  */  public class Adapter extends Target { 	/** reference to the object being adapted */ 	private Adaptee adaptee;  	/** 	 * @param adaptMe 	 *            class to adapt whis this adapter 	 */ 	public Adapter(Adaptee adaptMe) { 		this.adaptee = adaptMe; 	}  	/** 	 * Implementation of target method that uses adaptee to perform task 	 */ 	public void request() { 		adaptee.specificRequest(); 	}  }  /**  * This class defines domain-specific interface used by client  *   * @role __Target  */  public abstract class Target { 	/** This method is called by client when he needs some domain-specific stuff */ 	public abstract void request(); } 

About The Author

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