How to handle the 'this' link in a decorator template

I have a problem in my class that uses a decorator pattern.

The problem occurs when the internal object uses the "this" link when calling other objects. This leads to the fact that all calls from the object that received the "this" link must be made directly to the internal object, without going through the external one first.

What is the usual way to solve this problem?

Thank.

+5
source share
3 answers

: ( , ==). , ( , , ). , , - - . . Object getIdentity(), , , ==.

, == , . , :

  • , (identity == decorator identity == decorator.getIdentity())
  • ( - , )

, , , , :

protected Object getIdentity() {
    return this;
}

==, , .

+2

, . , , , .

( ) . , - : . , this

+1

, , . ( , ). , , .

-, ( , n- ). .

, , , , .

, (- ), , , . .

+1
source

All Articles