Created
May 31, 2012 11:21
-
-
Save sanpingz/2842754 to your computer and use it in GitHub Desktop.
代理模式
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.mceiba.util.Print.*; | |
interface Interface{ | |
void doSomething(); | |
void somethingElse(String arg); | |
} | |
class RealObject implements Interface{ | |
public void doSomething() { println("doSomething"); } | |
public void somethingElse(String arg) { println("somethingElse "+arg); } | |
} | |
class SimpleProxy implements Interface{ | |
private Interface proxied; | |
public SimpleProxy(Interface proxied) { this.proxied = proxied; } | |
public void doSomething(){ | |
println("SimpleProxy doSomething"); | |
proxied.doSomething(); | |
} | |
public void somethingElse(String arg) { | |
println("SimpleProxy somethingElse "+arg); | |
proxied.somethingElse(arg); | |
} | |
} | |
public class Proxy{ | |
public static void consumer(Interface iface){ | |
iface.doSomething(); | |
iface.somethingElse("bonn"); | |
} | |
public static void main(String[] args){ | |
consumer(new RealObject()); | |
consumer(new SimpleProxy(new RealObject())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment