In Java, is there a performance gain in using interfaces for complex models?
Posted
by Gnoupi
on Stack Overflow
See other posts from Stack Overflow
or by Gnoupi
Published on 2010-04-14T12:41:40Z
Indexed on
2010/04/14
13:13 UTC
Read the original article
Hit count: 198
The title is hardly understandable, but I'm not sure how to summarize that another way. Any edit to clarify is welcome.
I have been told, and recommended to use interfaces to improve performances, even in a case which doesn't especially call for the regular "interface" role. In this case, the objects are big models (in a MVC meaning), with many methods and fields.
The "good use" that has been recommended to me is to create an interface, with its unique implementation. There won't be any other class implementing this interface, for sure. I have been told that this is better to do so, because it "exposes less" (or something close) to the other classes which will use methods from this class, as these objects are referring to the object from its interface (all public methods from the implementation being reproduced in the interface).
This seems quite strange to me, as it seems like a C++ use to me (with header files). There I see the point, but in Java?
Is there really a point in making an interface for such unique implementation? I would really appreciate some clarifications on the topic, so I could justify not following such kind of behavior, and the hassle it creates from duplicating all declarations.
Edit: Plenty of valid points in most answers, I'm wondering if I won't switch this question for a community wiki, so we can regroup these points in more structured answers.
© Stack Overflow or respective owner