Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I mean something along the lines of:

public interface Dimensioned {
    int getWidth();
    int getHeight();


public interface Positioned {
    int getX();
    int getY();

There are a lot of standard java classes that have exactly those methods-- notably Component and all of its subclasses as well as Dimension and Point. Image could implement Dimensioned.
Despite the widespread use of these methods, there's no uniform way of referring to them. Is this a conscious decision on the part of the language designers? In writing this question, I've noticed that it is rather difficult to come up with good descriptive names for the interfaces. Even so, it feels like it would be useful to have them. I can't seem to find much information on the topic.

share|improve this question
If you're already subclassing Point, why would you need an additional interface? – Robert Harvey Dec 31 '12 at 18:15
But what about multidimensional applications? Two may not be enough. :-) – Spoike Dec 31 '12 at 20:09
And what about Points that have floating point values? (Indeed, OpenCV has a generic Point class that can be specialized for all dimensions and value types.) – rwong Jan 1 '13 at 7:46

Interfaces aren't just some means to group classes together that happen to have common function names, they must have some value to the code that calls the functions. You would need a compelling use case for having something like a Vector<Dimensioned> and calling getWidth() on all of its elements, whether they're components or something else. It's easy to come up with use cases for a Vector<Component> or a Vector<Image>, but not a mixed bag of both. Feeling "like it would be useful" isn't a compelling reason.

share|improve this answer
Perhaps not for Dimensioned, but what about an interface that included setWidth() and setHeight() as well? With that, you would be able to write resizing algorithms independent of class. – Kyle Buzsaki Dec 31 '12 at 21:26
@KyleBuzsaki: Component already has a setSize function. For example, if you're working with Swing, you can already just pass around Vector<Component>. If you're working with your own graphical primitives, they probably either inherit from Component, or are sufficiently different from Component that sharing an interface with Component is of low value. – Brian Dec 31 '12 at 22:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.