使用Decorator模式实现的Java继承(Java Inheritance implemented with Decorator pattern)

编程入门 行业动态 更新时间:2024-10-25 22:33:37
使用Decorator模式实现的Java继承(Java Inheritance implemented with Decorator pattern)

认为在引擎盖下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

更多推荐

本文发布于:2023-07-27 15:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292424.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   Java   Decorator   pattern   implemented

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!