Sometimes the interface is half-empty
Last morning I spent some time thinking about what to do when I want to reference an instance of a class by its interface but I need to use the powers of two separate interfaces.
A more experienced co-worker suggested that I write a new interface that declares no methods (i.e. empty) and inherit from both of the required interfaces, however, this solution seems clunky to me. I alway thought of interfaces as contracts that specify a behavior on the part of the implementing class, and a method of avoiding the brittleness and limitations of deep class hierarchies. By that logic, creating empty interface hierarchies to work around scope creep seems to obviate everything that is elegant about interfaces.
In surfing the web for alternative guidance, however, I found empty interfaces commonly used for a variety of reasons by programmers with far more experience and education in the dark arts than myself; tagging classes for semantic purposes and enforcing standardization at compile time being among some of those reasons. And while personally I would agree with none of these uses, I have to admit defeat and recongnize that while an inherited empty interface may not define any behaviors and impose unecessary restrictions down the line, it can serve a purpose.
(For the record, I still reserve the right to call it clunky.)
A more experienced co-worker suggested that I write a new interface that declares no methods (i.e. empty) and inherit from both of the required interfaces, however, this solution seems clunky to me. I alway thought of interfaces as contracts that specify a behavior on the part of the implementing class, and a method of avoiding the brittleness and limitations of deep class hierarchies. By that logic, creating empty interface hierarchies to work around scope creep seems to obviate everything that is elegant about interfaces.
In surfing the web for alternative guidance, however, I found empty interfaces commonly used for a variety of reasons by programmers with far more experience and education in the dark arts than myself; tagging classes for semantic purposes and enforcing standardization at compile time being among some of those reasons. And while personally I would agree with none of these uses, I have to admit defeat and recongnize that while an inherited empty interface may not define any behaviors and impose unecessary restrictions down the line, it can serve a purpose.
(For the record, I still reserve the right to call it clunky.)
