Re: Design Question
Ian Joyner <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
I'd make a static class accessing all your codes, something like:
abstract public class XCodes {
public XCodes () {
load_dictionary ();
}
protected NSDictionary /*[Integer, String]*/ codes;
public String description (int code) {
return codes.objectForKey (new Integer (code));
}
abstract load_dictionary ();
}
public class Allergy_codes extends XCodes {
load_dictionary () {
// load your codes dictionary here.
}
}
public class Codes {
public static Allergy_codes allergies;
public static Injury_codes injuries;
...
static {
// Do some static initialization here.
}
}
That way, you can get at all your codes from anywhere through the
static Codes class:
String s = Codes.allergies.description (83);
It's probably not strictly correct, but anyway you get the idea that
you can partition your common data into static classes using static
fields and static initializers (sort of does the once routines of
Eiffel, but maybe not so neatly). So actually, there's nothing WO
about this, it's all Java.
Ian
On 21/07/2006, at 11:00 AM, Michael Deninger wrote:
> I have a design question that I would like to bounce off some of
> you more experienced WO developers..
>
> I have some static data that I need to access from within an
> EOGenericRecord. The data, unfortunately, is not in the DB (and
> even if it were, creating a relationship to the entity would likely
> not work for various reasons). The data is essentially a dictionary
> of keys / values that describe the meaning of the coded values in
> one of the database tables. E.G.
>
> Entity: PatientAllergy
> Attribute: AllergyCode
>
> where AllergyCode is some number (say 83). The meaning of that
> number is in this dictionary (e.g. value = 83, description =
> "penicillins")
>
> What is the best way to accomplish this? I have considered the
> following:
>
> 1) read this dictionary into my Application object at startup.
> Sounds great, but I cannot figure out how to access EOApplication
> from an EOGenericRecord
> 2) read this dictionary form disk into each EOGenericRecord at the
> time it is created. I think that this would work, but it creates a
> lot of unnecessary repetition of data.
> 3) hard-code the dictionary into an abstract class extending
> EOGenericRecord and have the Entity inherit from it.
>
> Obviously, I would love to use 1) but I am stuck as I describe
> above...
>
> Is there any way to accomplish number one or are there other
> alternatives that I have not thought of or considered?
>
> Thanks!
>
> Mike
> _______________________________________________
> WebObjects-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/webobjects-dev
>