Re: Defining a constructor in an Interface



Lee Fesperman wrote:
Thomas Weidenfeller wrote:

Chris Smith wrote:

That said, I don't think there's ever a good excuse for requiring a
constructor that takes parameters.

Well, such a requirement, or lets better say nice-to-have feature, can come up when you want to have a 1:1 translation of your design model to an implementation. I perfectly understand (at least I think so) why things are as they are, but it would be nice to have it otherwise.


Nope, it's still a bad idea. A decent implementation is likely to want additional arguments to its constructor. It pretty much kills multiple inheritance of interfaces because of conflicting constructor requirements. If your implementation wishes to extend another class with specific constructor requirements, you have no recourse.


Just because there are drawbacks, doesn't make it a bad idea. First of all, if such a thing were added to the language, interfaces wouldn't necessarily be required to specify a constructor signature. So everything that exists currently would still work exactly as it does. Second, if one were to use said functionality, one would have to be aware of the implications (as indicated in your post).


That said, I think we can live without this particular feature in the Java language.

Ray

--
XML is the programmer's duct tape.
.



Relevant Pages