For conversations sake, lets assume I am developing a web application (no ejb) which has a domain object called Address and Address has a property, stateId.
What is the most common way of translating this id into its corresponding value (stateId 1 = Ohio)? More specifically, where (what layer) should this code reside? It is very common to present the user with a drop down list box with all the valid values. I have not come across any discussions as to where this code belongs. Is it better to put a method on the domain object itself which will retrieve this id's corresponding value? What about a list of all valid values? Is it better to put all name/value resolution code in a DAO who's job is to look up these values? If these values are finite, could anyone suggest any caching strategies that they have found useful?
I think this example is about rendering, so i would translate id to string as late as possible (jsp code), and the mapping should be defined completely independant of your core domain, because your business logic doesn't ever need the name (except for rendering), so it shouldn't contain code for it. It should be in a code part that belongs to the layer "rendering my application somehow", which would also contain gui terminology.
I would have a singleton responsible for the management of the mapping, when & how to load mappings or release parts of it. It could be programmed as a generic thing that just needs a table in a database, and is tunable in behaviour.