【发布时间】:2016-04-18 07:06:13
【问题描述】:
我有一个派生自 ButtonModifier 的 VolumeButton。如果我将业务逻辑(音量增大/减小、静音等)放入 VolumeButton,启用/禁用基类 ButtonModifier 的逻辑。喜欢,
public class VolumeButton : ButtonModifier
{
/// Event handler to change the volume.
void ChangeVolume() { ... }
}
public class ButtonModifier
{
/// Updates the visibility of the button.
void UpdateVolumeVisibleStatus() { ... }
/// Enable or disable the button.
void Enable(bool enable) { ... }
}
一方面,只有业务逻辑更改会影响 VolumeButton,而基础架构更改会影响 ButtonModifier。所以它符合SRP。另一方面,VolumeButton 从基类继承了启用/禁用逻辑。那么它有两个职责?
这两个类是否符合SRP?
【问题讨论】: