认为在引擎盖下java继承是正确的 使用Decorator Pattern实现? 在我看来,继承和装饰模式看起来非常相似,几乎无法区分。
编辑: 我的意思是,让A成为B的子类,我们可以说在A中关键字super总是引用类型A的对象,我们是“装饰”。
谢谢
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
最满意答案
inheritance和decorator pattern的共同之处在于它们都允许您更改对象的行为方式。 而且,更准确地说, decorator pattern是通过inheritance的概念实现的。
但区别在于:
1. Decorator pattern使运行时对象更改更容易:
2. Decorator Pattern使多个行为修改更容易
在非动态情况下, Decorator pattern不是必需的
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
更多推荐
发布评论