1 Public classTestproxy {2 Public Static voidMain (string[] args) {3Object obj =Newproxyobject ();4 obj.action ();5 }6 }7 8 Interfaceobject{9 voidaction ();Ten } One //proxy class A classProxyobjectImplementsobject{ - Object obj; - the PublicProxyobject () { -SYSTEM.OUT.PRINTLN ("proxy class creation succeeded"); -obj =NewObjctimpl (); - } + - Public voidaction () { +SYSTEM.OUT.PRINTLN ("proxy class start Execution"); A obj.action (); atSYSTEM.OUT.PRINTLN ("proxy class execution End"); - } - } - //by proxy class - classObjctimplImplementsobject{ - in @Override - Public voidaction () { toSystem.out.println ("===== the proxy class starts executing ======"); +System.out.println ("===== Specific operation ======"); -System.out.println ("===== has been executed by the proxy class ======"); the * } $ Panax Notoginseng}
Java Learning-The application of interfaces: Proxy mode