Re: Separation of API and implementation



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.



.



Relevant Pages

  • Re: MVPs: static methods in interfaces. (REDEFINED)
    ... this static method is public and therfore should be publicly known ... >> code to define a behavior (the interface) and another body of code to ... >> Abstract Factory pattern describes. ... >> programmer helping programmers. ...
    (microsoft.public.dotnet.languages.csharp)
  • C# Plugin system - same interface in two different assemblies...
    ... I am now aware that in C# if you reference the same interface from the same file in two different projects the types are actually incompatible. ... I found this out because I have written a generic plugin system for my current and future C# needs. ... When you compile and build both projects (we haven't even defined an interface which inherits from IPlugin yet, lol) and run the host.exe application, the host creates an instance of the plugin manager and tells it to load the dll produced by the MyPlugin project. ... This means that the runtime considers the interface IPlugin, which is of course defined in both assemblies so that each assembly can use it, to be different in each assembly. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Separation of API and implementation
    ... I have an API defined in one plugin, ... interface X { ... Think about what the primary characteristic of all plugins is: it provides services that one can plug it into various client contexts. ... IOW, it isn't a plugin if any of these things is not true. ...
    (comp.object)
  • Re: How to use interfaces properly...
    ... > MyInterfaceTest). ... > property on the reference to "false". ... > interface have to have its own copy of the dll that contains the ... > references that will work during development, but will also let the plugin ...
    (microsoft.public.dotnet.framework)
  • Re: [linux-pm] Power Management framework proposal
    ... the software needs to know what the interconnects and dependancies ... > so that one can make a plugin specific for each device. ... > i believe there is no way to do an abstract interface for this and trying to ... there power management tunning capacity, Then an ohm plugin would use ...
    (Linux-Kernel)