Bridge Print E-mail
User Rating: / 1
PoorBest 
Thursday, 20 January 2005 21:15
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();
}

Tags See All Tags Add New Tag...

Please Enter New Tags Separated By Comma's
  Or Close

designpattern  java 
Powered By Joomla Tags

Comments
Add New Search RSS
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:):grin;)8):p:roll:eek:upset:zzz:sigh:?:cry
:(:x
Please input the anti-spam code that you can read in the image.

3.20 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated on Saturday, 18 June 2005 00:10
 
Content View Hits : 3463460

Enter Amount: