JavaFX and the Missing Interfaces
Randahl Fink Isaksen
randahl at rockit.dk
Wed Nov 7 03:14:56 PST 2012
I think these are very nice suggestions. I had not thought about the <T extends Control & IControl> idea.
However, I would still prefer framework code like this
public void doSomething(IControl control) {
double width = control.getWidth();
}
where IControl extends SceneNode, because it rids me from having to flood the whole framework with the T extends Control & IControl.
It is an interesting work around. But a work around nonetheless.
Randahl
On Nov 6, 2012, at 18:36 , Anthony Vanelverdinghe <anthony.vanelverdinghe at gmail.com> wrote:
> +1
>
> Adding generics you 'd get:
> interface IControl<T extends Control> {
> T getControl();
> }
>
> Another option is to rewrite your method signatures from
> public Something fooBar(IControl control) {...}
> to
> public <T extends Control & IControl> Something fooBar(T control) {...}
>
> So there are already solutions to the problem. In my opinion, interfaces like the ones proposed are neither necessary nor desired (as Richard already pointed out, they would unnecessarily clutter the API).
>
> Kind regards
> Anthony
>
> Op 5/11/2012 21:46, Pedro Duque Vieira schreef:
>> I've read your blog post.
>>
>> May I suggest doing:
>>
>> Interface IControl
>> {
>> Control getControlRepresentation();
>> (...)
>> }
>>
>> This way you enforce every implementing class to have a Control
>> representation. And also as a plus you don't need to recur to casting when
>> you need to call methods from Control, because you can get a Control
>> representation via getControlRepresentation(). This is basically
>> composition instead of inheritance, which I think IMHO is better most of
>> the time.
>>
>> Also one more note, the methods of the API are final because of security
>> reasons. I guess Java is to blame for this.
>>
>> My 2cents, best regards,
>
More information about the openjfx-dev
mailing list