Support

Forums

Contact Me

Proxy

Provide a surrogate or placeholder for another object to control access to it. Options are provided to implement all interfaces of the subject class as well as all of the public methods of the subject class



Source Code

/**
 * Represents a proxy for Subject
 */
public class Proxy extends Subject {
	/**
	 * Holds the subject instance.
	 */
	private Subject subject;

	/** @see patterns.gof.proxy.Subject#sampleMethod() */
	public int sampleMethod() {
		return subject.sampleMethod();
	}
}

/**
 * Represents a real subject
 */

public class RealSubject extends Subject {
	public int sampleMethod() {
		/* something happens here */
		return 0;
	}
}

/**
 * Represents a subject
 * 
 * @role __Subject
 */

public abstract class Subject {
	/**
	 * This is sample method to be called by proxy
	 */
	public abstract int sampleMethod();
}
You might also like:
Flyweight
3043 days ago
Flyweight
Use sharing to support large numbers of fine-grained objects efficiently.Source Code/** * Declares
Adapter
3043 days ago
Adapter
Convert the interface of a class into another interface clients expect. Adapter lets classes work to
Decorator
3043 days ago
Decorator
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternati
Bridge
3043 days ago
Bridge
Decouple an abstraction from its implementation so that the two can vary independently.from the gang
blog comments powered by Disqus

Donations

Thank You for supporting my work