[ 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.
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".
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.
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
But the difference:
Decorator pattern makes run-time object changes easier:
Decorator Pattern makes multiple behavior modifications easier
Decorator pattern is not necessary in non-dynamic situations