aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Suggestion Needed on Preferred Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Suggestion Needed on Preferred Pattern" Watch "Suggestion Needed on Preferred Pattern" New topic
Author

Suggestion Needed on Preferred Pattern

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Guys,

I have a very simple question with regards to the best or favorable approach for handling system wide constants. Here is the scenario:

I have an application in which there are quite a few application wide constants defined. Some of these constants have also a meaning in the relational model. For example., it will be defined in a master table and will be referenced in one of the transaction table. My application logic or rather the domain would also require to process some logic based on these constants. Normally the approaches that I have implemented so far will consist of a static class that will hold these constants. But is there a better or alternate way to do this?


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
For example., it will be defined in a master table and will be referenced in one of the transaction table.


Here you are talking about storing the value of the constant variable in a relational table, is this correct?

Normally the approaches that I have implemented so far will consist of a static class that will hold these constants.


Here the static class has variables that consist of values derived from database table mentioned above, is this correct? Or, are the values hard-coded in the class definition?


So far, it looks like using a static class is not the best way. A simple data object with it's members populated from values in the database should be sufficient.

A static class with hard-coded values would be appropriate if the values are only used by objects.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

You are absolutely right in what you understood from my post above.

I also do not want to populate the data object with the values from the database every time I need it. But instead, read it once and populate the static class with the values read from the database. This has been my approach so far. But is there an even more better way to do this?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
In order to determine a "better" way or if this is the "best" way, further detailed analysis of the application would be required.

Is there any significant problem with your current approach?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

There are no significant problems. But in most of the projects that I worked, more or less the same pattern was followed. So just though of doing it in an alternate way and started exploring if some design patterns might be of help.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Ok. Just to clarify, storing data in a relational table and using this data to populate data members of an object is not an object-oriented design pattern. It is simply a "technique."

Object-oriented design patterns typically handle "commonly occurring problems" and are named and documented in accord with a prescribed format.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Suggestion Needed on Preferred Pattern
 
Similar Threads
Implemetinng the interface with all static final variables
Interface - Jargon
String constants
OJB - Mapping a table w/o Primary Key
SQL statements in files in jars - best practice suggestions?