Same 2 methods for each class variable for each Domain object. What is the smart way to design this.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Gibberish_Driftwood
Posted On:   Monday, June 9, 2008 03:20 PM

I have a set of Domain classes. These are just simple beans with private class variables which each have their own getter and setter. These domain objects will be stored in a persistant store. Now I also need to store the date/time and in which context (String value) the last set method was called. So for each class variable two values releated to the set method call. I could of course add two variables to next to each class variable, like private String classVariable1; private Date classVariable1_LastSet; private String classVariable1_ContextLastSet; public Date getClassVariable1_LastSet() {...} But as I have mul   More>>

I have a set of Domain classes. These are just simple beans with private class variables which each have their own getter and setter. These domain objects will be stored in a persistant store.



Now I also need to store the date/time and in which context (String value) the last set method was called. So for each class variable two values releated to the set method call.



I could of course add two variables to next to each class variable, like

			
private String classVariable1;

private Date classVariable1_LastSet;

private String classVariable1_ContextLastSet;



public Date getClassVariable1_LastSet() {...}


But as I have multiple class variables and multiple Domain classes this would not be the simplest way. I have bean looking into the Decorator class but I just don't see the complete solution.


Anyone got any brilliant ideas ?

THX    <<Less

Re: Same 2 methods for each class variable for each Domain object. What is the smart way to design this.

Posted By:   Stephen_McConnell  
Posted On:   Tuesday, June 10, 2008 03:10 PM

You need to persist the "date" in some format in your database. Usually the correct way to do this is in Java and most Databases is to save it as a Date or Timestamp DB object. And this is how I would keep it in my domain objects. No need to keep multiple copies of them in different formats... This leads to possible problems and a lack of "normalization"...


What I have done is write a Utility Class with a bunch of static methods on it. It's part of my toolbox when I write Java apps and will have a static method for converting back and forth between the various formats I need... It has methods for calculating date differences... etc etc...


I don't know if this is the best design pattern, but it's what I use...


Stephen McConnell

About | Sitemap | Contact