GionJh
GionJh

Reputation: 2894

Java Inheritance implemented with Decorator pattern

Is it right to think that under the hoods java inheritance
is implemented using Decorator Pattern ?
In my mind inheritance and Decorator Pattern look very similar almost indistinguishable.

EDIT:
I mean, let A be a subclass of B,we can say that in A the keyword superalways refers to the object of type A we are "decorating".

Thanks

Upvotes: 0

Views: 187

Answers (2)

OPK
OPK

Reputation: 4180

What inheritance and decorator pattern have in common is the fact that they both allow you to change how an object behaves. Also, to be more precise, decorator pattern is implemented by the concept of inheritance.

But the difference:

1.Decorator pattern makes run-time object changes easier:

2.Decorator Pattern makes multiple behavior modifications easier

3.Decorator pattern is not necessary in non-dynamic situations

Upvotes: 1

Alex
Alex

Reputation: 21766

I doubt Java implements inheritance under the hood using the Decorator pattern. Relationships between base classes and their extensions are fixed at compile time, whereas relationships between decorators and the objects they decorate can change at run time.

Upvotes: 0

Related Questions