A Pattern for Extending Java Enums (Applied to Astronomy)

As part of my employer’s Software Engineering Tech Trends series, I have written an article on A Pattern for Extending Java Enums. In the article, I describe and use a pattern for sharing logic between different Java Enums to calculate the orbital period and surface gravities of several objects in our Solar System (thanks to Dr. Pamela Gay and Fraser Cain of the Astronomy Cast podcast for the astronomical inspiration).

Previously, I have written articles in the series on an Intro to JGoodies Forms, Units and Measures with JScience, an Intro to JGoodies ValidationWriting Music in Java: Two ApproachesA Better Date and Time API: Joda TimeHighlights of Apache Commons Lang, Part 1, Highlights of Apache Commons Lang, Part 2, Project Coin: Small Changes in JDK 7, and Design by Contract in Java with Google.

Check it out!

Advertisements

About Lance Finney

Father of two boys, Java developer, Ethical Humanist, and world traveler (when I can sneak it in). Contributor to Grounded Parents.
This entry was posted in Programming and tagged , , , , . Bookmark the permalink.

2 Responses to A Pattern for Extending Java Enums (Applied to Astronomy)

  1. Frisian says:

    Really nice article. Java Enums are seriously underestimated in my opinion.
    One thing, though:
    The actual calculation of the orbital period should be moved to the Util class as a static function with semiMajorAxis and parentBodyMass as parameters. It would separate the actual calculation from gathering the arguments. BTW, “parentBody.getProperties().getMass()” could be considered in violation of the Law of Demeter.
    Because this is also the only place, where the gravitaional constant is used, it could be moved to the Util class as well.
    Constants in an interface don’t define functionality of an implementing object, so I consider them a code smell.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s