Interface

Hi all,

Is there a way(a keyword) to say to one interface that it must be implemented by maximum one class (stub class)?

I would like to put a restriction for the developers in such way they cannot implement that interface but they must extend the stub class (that it is the only one to have implemented that interface)

Thank you,

best regards.

Raffaele

[390 byte] By [Gamby1980a] at [2007-10-2 22:01:54]
# 1
No.Disregarding the reasons why you wish to do this and whether it's a good thing or not, if you want to do this then it sounds like your interface is adding no value to the design. Get rid of it. Just use the abstract base class instead.Or... review your design...
dannyyatesa at 2007-7-14 1:18:12 > top of Java-index,Core,Core APIs...
# 2

Probably your ansewer is right.

However the main reason is that every developer in front of an interface, must implement all the methods declared in it, often defining some methods with empty body.

Therefore I would like to define one stub class that implements the interface defining all empty methods, then I would say to all develoeper to extend that class implementing what they need.

Thank you for the answer,

best regards

Raffaele

Gamby1980a at 2007-7-14 1:18:12 > top of Java-index,Core,Core APIs...
# 3

In that case, you should question the design of your interface. If some methods are optional perhaps they belong in a different interface? At the very least, docmuent them as original. There are several methods in the collections framework that are optional and different implementations chose whether to implement them or not.

Plus, with modern IDEs, there's not really any great hardship for developers to implements stubs methods.

dannyyatesa at 2007-7-14 1:18:12 > top of Java-index,Core,Core APIs...
# 4
having adapter classes might be a good idea for listeners but not in the case you have described. I would rather go back and revise the design
kilyasa at 2007-7-14 1:18:12 > top of Java-index,Core,Core APIs...