Hi, I am trying to find an easily extended way to write compose
concrete objects for my application.
The objects I am using are all things (nouns) like Customer, Database,
Shop, Task, Year, etc. etc. LOTS of classes like this.
I have GUI components (Tapestry) that display messages regarding the
object or objects.
I want to be able to do something like Customer.plural to get the
String "Customers". I'd like these conjugates available statically,
so no instance is needed (In case the object is null)
I have 4 conjugates for each noun: singular, plural, singular
possessive, plural possessive.
Furthermore, sometimes the GUI components can work on many different
types of these objects, so the class should not be hard-coded in the
component. It should code something like:
Noun.plural to get the String "Customers"
But we can't override static fields.
Of course the concrete classes each have unique fields, along with a
getLabel() method which generates a String for identifying each
instance.
They also have getId() which is a code that uniquely identifies the
object (used for compare,equals,hashcode)
Any Ideas?
Roedy Green - 05 Nov 2007 21:22 GMT
>Of course the concrete classes each have unique fields, along with a
>getLabel() method which generates a String for identifying each
>instance.
You need a Grammar class that takes a root and produces the various
variants. You write your rules then have HashMap of exceptions that
you add to as you discover them when the rules fail.
Your static methods would be wrappers for this Grammar class.
You might use Class.getName to get you the root string.
What is the slickest way to get hold of the Class object for the
current class in a static method? an instance method?

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 05 Nov 2007 21:53 GMT
> Hi, I am trying to find an easily extended way to write compose
> concrete objects for my application.
[quoted text clipped - 10 lines]
> I have 4 conjugates for each noun: singular, plural, singular
> possessive, plural possessive.
How about a ResourceBundle that defines each of those four names off a key for
each class? The class can look up its plurals and possessives for display
purposes.
bundle.getString( Task.getPluralPossessiveKey() )

Signature
Lew