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?

  • 2
    "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, 2012 at 15:17

2 Answers 2


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.

  • YAGNI: You Aren't Going to Need It
    – James
    Oct 25, 2012 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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