Differing implementations for a function in two interfaces
Lionello Lunesu
lio at lunesu.remove.com
Sun Apr 16 23:28:14 PDT 2006
Consider this:
Two interfaces are part of different third party modules. One module
wants you to provide an implementation for interface IA and a completely
different module needs some interface IB. They are completely unrelated.
No problem at all. Your application class can easily interface with both:
class C : IA, IB
{
// implement all of IA's methods
...
// implement all of IB's methods
...
}
And you provide cast(IA)this to module A and cast(IB)this to module B.
No worries.
After some time, a new version has come out for both the third party
modules, each with some added functionality. However, all programmers
being human (last time I checked) they're pretty bad at randomness and
they both declared a method "int get()" in their interfaces.
Now you're in trouble. There's no way you can provide one implementation
for both "int get()"s, since they are completely unrelated. IA.get is
used in a completely different context from IB.get.
Now what? Redesign the whole app and make multiple classes? I wish there
was another way.
L.
More information about the Digitalmars-d-learn
mailing list