Re: Subclass final class (Boolean) ?
Re: Subclass final class (Boolean) ?
- Subject: Re: Subclass final class (Boolean) ?
- From: Steve Quirk <email@hidden>
- Date: Sun, 27 Aug 2006 11:40:40 -0400 (EDT)
On Sun, 27 Aug 2006, Ken Anderson wrote:
OK, I'm a little annoyed here because I find the whole concept of 'final' to
be ridiculous.
I would like to subclass Boolean so that I can initialize it (class method)
with a short string (valueOf:"t" instead of valueOf:"f") and also to return
"t" and "f" for toString (or some other method like toShortString()).
Unfortunately, java.lang.Boolean is marked as final. Is there any way to get
around that?
To give a little background, I would like to have a custom WebObjects type
where I can declare the factory method to create the instance, and the method
to call to get back the string instance. I want to make it a single
character so that I can use a string field with length=1 instead of length=5
(saving a lot of space).
Oh, and yet another reason I want categories from Objective-C in Java...
Thanks,
Ken
Hi Ken,
For a more complex class with several values, it might make sense (a
single letter indicating eye color, for instance). But DBs have lots of
examples with a two-value true/false column - all in the same schema.
What do you do for the other tables in your DB that use 1 and 0 (Number)
or 'Y'/'N' (char(1)) or 'A'/'D' (char(1) - "Alive"/"Dead") to represent
true and false? A dozen subclasses of Boolean in the same app? Your
coworkers and those who follow you to maintain your app will be grabbing
the pitchforks and lighting the torches to come & hunt you.
Just give in and do what everyone else does. In your entity class, hold
your nose and code something like:
private static final Character TRUE = new Character('t');
private static final Character FALSE = new Character('f');
boolean rancid; // column RANCID char(1), 't' = TRUE
public void setRancid(boolean aBool) {
value = aBool;
}
public void setRancid(Character aChar) {
setRancid(TRUE.equals(aChar));
}
public Character getRancid() {
return (rancid) ? TRUE : FALSE;
}
public boolean isRancid() {
return rancid;
}
...
TRUE/FALSE is just too easy to code around. Keeping the simple things
final might not be a bad idea.
- sq
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden