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

In java (and many other programming language), there are often structure to deal with graphic element : Colour, Shape, etc. Those are most often in a UI toolkit and thus have a relatively strong coupling with UI element.

Now, in the domain of my application, we often deal with colour, shape, etc, to display statistic information on an element. Right now all we do with it is display/save those element with little or no behaviour. Would it make sense to avoid "reinventing the wheel" and directly use the structures in java.awt.* or should I make my own element and avoid a coupling to this toolkit? Its not like those element are going away anytime soon (they are part of the core java library after all), but at the same time it feel weird to import java.awt.* server side. I have no problem using java.util.List everywhere. Should I feel different about those class?

What would be the "recommended" practice in that case?

share|improve this question
"recommended practice" for stuff like that is to use code reviews to find out how good is your application design. "- How would you know if you've written readable and easily maintainable code? - Your peer tells you after reviewing the code." – gnat Oct 24 '12 at 15:17
up vote 1 down vote accepted

I would apply YAGNI here and use the structures from the standard library, however I would be careful to ensure all parts of the domain using this stuff are as close together in the system as possible. This will make searching out the usage for replacement later trivial in case you do end up needing a decorator on top of these structures.

You don't want these structures to end up spread all over your code base unless you're absolutely certain the requirements of them will never change (hint: requirements of every piece of code you ever write will always change). I guess I should also say, if their only purpose is for the code to be used by client side pieces which rely on the java standard implementations then you're probably safe treating them as primitives.

share|improve this answer
YAGNI: You Aren't Going to Need It – James Oct 25 '12 at 15:36

As long as you don't persist it. Once you're making RDBMS schema to hold the structure, you should rethink your approach.

share|improve this answer

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.