gpt4 book ai didi

Java:混合实现类

转载 作者:行者123 更新时间:2023-12-03 21:27:51 29 4
gpt4 key购买 nike

我在几个名为 Mixin 的代码库类中看到了如下注释:

//Mixin style implementation
public class DetachableMixin implements Detachable {}

这种实现方式下的概念是什么?

最佳答案

这是 Joshua Bloch “Efective Java”中的一段引用(我不认为,我自己可以更好地解释它):

Interfaces are ideal for defining mixins. Loosely speaking, a mixin is a type that a class can implement in addition to its “primary type” to declare that it provides some optional behavior. For example, Comparable is a mixin interface that allows a class to declare that its instances are ordered with respect to other mutually comparable objects. Such an interface is called a mixin because it allows the optional functionality to be “mixed in” to the type’s primary functionality. Abstract classes can’t be used to define mixins for the same reason that they can’t be retrofitted onto existing classes: a class cannot have more than one parent, and there is no reasonable place in the class hierarchy to insert a mixin.

关于Java:混合实现类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47347027/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com