Re: Separation of API and implementation
- From: "Gabriel Claramunt" <gabclar@xxxxxxxxxxxxxxx>
- Date: Wed, 15 Aug 2007 20:25:02 -0400
I'm missing something or an Abstract Factory could help?
As long as you use the factory, you can ensure that your implementation of X
will use your implementation of Y.
--
Gabriel Claramunt
http://gabrielsw.blogspot.com
<hforco2@xxxxxxxxxxxxxx> wrote in message
news:1187099893.988357.302270@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm programming in Java, actually developing plugins in Eclipse, but I
think the general questions are relevant not only to Java.
I have an API defined in one plugin, in a set of packages. Call this
plugin A.
Another plugin contains my implementation, in a set of different
packages. Call this plugin B.
I have interfaces X and Y in A where X is defined as follows:
interface X {
void foo(Y y);
}
Now I implement X in B as follows:
class XImpl implements X {
public void foo (Y y) {
// Do something with Y
}
}
The problem I have is the 'Do something with Y'. Y is an interface and
has been designed to be reasonably generic i.e. not specific to the
implementation B.
But the implementation in B only works if I assume Y is actually B's
implementation of Y, say YImpl.
So 'Do something with Y' becomes:
// Cast to my implementation:
YImpl myImpl = (YImpl) y;
This raises several questions:
Am I ok to assume the cast will work?
This is presumably quite a common problem. In cases like this, is it
accepted that you won't get more than one implementation being mixed
with another, i.e. if I get passed back an interface from A then I can
assume it is my B implementation?
And how do I deal with unit-tests which create mock implementations?
Thoughts/comments much appreciated.
.
- Follow-Ups:
- Re: Separation of API and implementation
- From: Daniel T.
- Re: Separation of API and implementation
- References:
- Separation of API and implementation
- From: hforco2
- Separation of API and implementation
- Prev by Date: Re: Separation of API and implementation
- Next by Date: Re: Pattern/s sought
- Previous by thread: Re: Separation of API and implementation
- Next by thread: Re: Separation of API and implementation
- Index(es):
Relevant Pages
|