Interface with member interface?
Let's say I am coding an C++ application which needs to drive some motors with some hardware interface (USB, Serial...). There are several kinds of motors, which expose the same services, but with different implementations. I could connect a concrete motor with one hardware interface among several possible interfaces. So I need an interface class for the motor, and an interface class for hardware communication. How to modelize that ? Should I have a class IMotor with a IHWCom* member ? I don't know if it is a good practice: in Java, an interface cannot have any member. But for me, as a implementation class deriving from IMotor should always have a dependency on an hardware interface for the communication, that should appear in the base class. SRP is so not relevant, because it doesn't make sense to have a concrete class of IMotor without hardware communication layer. The dependency could be added in each concrete class, but so we have some duplication, and a common feature is not visible anymore.
Let's say I am coding an C++ application which needs to drive some motors with some hardware interface (USB, Serial...).
There are several kinds of motors, which expose the same services, but with different implementations. I could connect a concrete motor with one hardware interface among several possible interfaces.
So I need an interface class for the motor, and an interface class for hardware communication.
How to modelize that ?
Should I have a class IMotor
with a IHWCom*
member ?
I don't know if it is a good practice: in Java, an interface cannot have any member.
But for me, as a implementation class deriving from IMotor
should always have a dependency on an hardware interface for the communication, that should appear in the base class. SRP is so not relevant, because it doesn't make sense to have a concrete class of IMotor
without hardware communication layer. The dependency could be added in each concrete class, but so we have some duplication, and a common feature is not visible anymore.
What's Your Reaction?