interface, interface client, vs inheritance, Software design principles, compoment packaging issue [closed]
I came across one issue as to how to package interface, interface client and inheritance. That is, in the book below, author mentioned that Switachable is more appropriate to deploy with Switch together as a component, rather than L开发者_Go百科ight.
What I want to understand is the reasoning behind it (Both Switch and Switchable are packaged in one component, rather Switchable and Light) , and example if possible.
I think there are cases where both scenarios are valid. One example that is oppoiste of that design is, IStream, FileStream are in one component, ISream client is in another component.
Below is from unclebob's agile in C# ch 33, p497.
Since Light
inherits from Switchable
, it could also be deployed with Switchable
- it seems, however, due to the naming, that the primary class interacting with the Switchable
interface will be Switch
- which means that the two are tightly-coupled: you should never put tightly-coupled class/interface definitions in separate assemblies.
You could also conceive of other Switchable
classes, such as Outlet
or a whole set of Appliances
. These could be added at a later date, and they would have nothing to do with Light
, meaning that Light
and Switchable
aren't necessarily part of the same component. However, the Switch
class would still apply to these new classes and would apply.
(It is true that a different consumer of the Switchable
interface could be conceived, but it would likely be an awkward adaptation, such as a ToggleButton
that toggled the on/off state by remembering the last method called. However, with the names chosen, Switchable
still implies that a Switch
could be involved.)
I hope this answers your question.
精彩评论