Seeing a very theoretical discussion on the BBS of ForumEye, as follows:
Composition composite:
Article 14 in "Efficient Java": Composite is preferred inherited.
code show as below:
Public class instructedset imports set {private final set s; private int address = 0; ..... PUBLIC INSTRUMENTEDSET (SET S) {this.s = S;} .... // forwarding methods (Forward) Public Void Clear () {S.clear ();} public boolean contains (object o) {Return S.Contains (0);} public boolean iSempty () {returnction ();} public int size () {returnof s. Size ();} .......
Delegation agent:
Code:
Delegatea {delegateeb B; void methoda () {b.Methodb (this);} void do () {}} DELEGATEEB {void methodb (delegatea a) {a. ();}} In the real world, if the chairman A Administration to General Manager B, General Manager B will definitely obtain the right of chairman A, which will use these rights to do things for the company. This is the real delegation, that is, Delegatee will call some methods of delegate, so you first have to pass Delegate to Delegatee.
The meaning of agency:
Delegation is a way of making composition as powerful for reuse as inheritance [Lie86, JZ91] In delegation, two objects are involved in handling a request:.. A receiving object delegates operations to its delegate This is analogous to subclasses deferring requests to parent classes . But with inheritance, an inherited operation can always refer to the receiving object through the this member variable in C and self in Smalltalk. to achieve the same effect with delegation, the receiver passes itself to the delegate to let the delegated operation refer to the Receiver
The Lord found some information on what is degecation: