Java Forum / General / February 2006
Singular and Plural Classes - conventions
VisionSet - 18 Feb 2006 13:15 GMT This will be familiar to most I imagine. You have an entity say a Person and you need to manage these so we have a Persons class. My projects are now becoming littered with 2 classes for most entities differing only by name with the final 'S'. Does anyone have another approach for this? I see many Apache projects do the same thing. Annoyingly it is so easy to pick the wrong class either to edit, mistype, look up javadoc for etc...
-- Mike W
Michael Redlich - 18 Feb 2006 13:34 GMT > You have an entity say a Person and you need to manage these so we have a > Persons class. > My projects are now becoming littered with 2 classes for most entities > differing only by name with the final 'S'. > Does anyone have another approach for this? I see many Apache projects do > the same thing. Hi VisionSet:
I need to know if I understand your question correctly...
(a) you have one class, Person, to model a single person. (b) you have another class, Persons, to model multiple people.
And you would like to know if there is a better way to do this, right?
Assuming that the above is correct, I would need to know if there are differences in state and behavior between the two classes. Are the Person and Persons classes abstract or interfaces?
Mike.
---- ACGNJ Java Users Group http://www.javasig.org/
Chris Uppal - 18 Feb 2006 14:12 GMT > You have an entity say a Person and you need to manage these so we have a > Persons class. > My projects are now becoming littered with 2 classes for most entities > differing only by name with the final 'S'. This is the first time I have ever heard of, or seen, such a pattern.
I presume that your Persons is not basically the same as, say, Set<Person>, or List<Person> (i.e. a completely vanilla holder of groups of Persons with no implied /reason/ for grouping them). But if not then I don't see why "Persons" is a good name for the class. What do its instances /do/ ? Given an instance of Persons, call it "persons", what is persons's job ? The name gives me no clue, so I suspect that the name is badly choosen.
-- chris
Raymond DeCampo - 18 Feb 2006 18:44 GMT >>You have an entity say a Person and you need to manage these so we have a >>Persons class. [quoted text clipped - 9 lines] > of Persons, call it "persons", what is persons's job ? The name gives me no > clue, so I suspect that the name is badly choosen. I think this is following the pattern used, for example, in the Java collections library. There is an interface Collection and a class Collections. As you probably know, the Collections class consists of static methods that operate on Collection instances. The java.beans.Beans class is another example, although there is no Bean interface.
HTH, Ray
 Signature This signature intentionally left blank.
Ed - 18 Feb 2006 22:24 GMT > This will be familiar to most I imagine. > You have an entity say a Person and you need to manage these so we have a [quoted text clipped - 8 lines] > -- > Mike W I must say that I, like other respondants, am unfamiliar with this terminology.
I do encounter the general, "Groupage," that I think you mean, but only very rarely. In a poker servlet I wrote, I had a clear need to access each Game; but also a clear need for some object to know (and create) all these games: this class I named, "GameGroup," though I suppose I could have just called it, "Games."
But that gives almost a definition of how rarely I come across what you describe: 95% of the poker code is Game-related; very little is involved in creating new games and timing-out old ones.
This littering you refer to seems strange.
.ed
-- www.EdmundKirwan.com - Home of The Fractal Class Composition
VisionSet - 18 Feb 2006 23:08 GMT > This littering you refer to seems strange. In retrospect littering is too strong a word, that and the fact I'm not great at coming up with great names, so the plural option is an easy option, especially when I hate overlong names. It also happens when I've skimped the design a bit and have lost a some cohesiveness. Thanks for the responses though.
-- Mike W
Andrew McDonagh - 18 Feb 2006 23:26 GMT >>This littering you refer to seems strange. > > In retrospect littering is too strong a word, that and the fact I'm not > great at coming up with great names, so the plural option is an easy option, > especially when I hate overlong names. The name should be as long as it needs to be to reveal its intent/purpose.
> It also happens when I've skimped the > design a bit and have lost a some cohesiveness. > Thanks for the responses though. yes, this is real cause of such unhelpful names.
There is usually a better name than adding 's' to it.
Person -> People Dog - PackOfDogs Car - CarPool Boy - Children
Mike Schilling - 19 Feb 2006 17:47 GMT >>>This littering you refer to seems strange. >> [quoted text clipped - 4 lines] > > The name should be as long as it needs to be to reveal its intent/purpose. There is an open source project I once contributed to which considered mandating short names for classes, methods and fields on the grounds that they would increase performance by making the class file smaller. I kid you not.
Andrew McDonagh - 19 Feb 2006 18:21 GMT >>>>This littering you refer to seems strange. >>> [quoted text clipped - 9 lines] > they would increase performance by making the class file smaller. I kid you > not. lmao
brilliant!
VisionSet - 19 Feb 2006 22:52 GMT > > There is an open source project I once contributed to which considered > > mandating short names for classes, methods and fields on the grounds that [quoted text clipped - 4 lines] > > brilliant! Sheer lunacy, however there comes a point where excessive class/variable name length becomes counterproductive. Personally I have a soft limit of about 25 char. I'd use more if it warranted it, but that would be unusual and I'd do my best to come up with something shorter.
Volume of code does IMHO reduce maintainability, that is without considering other factors. Of course good names improve maintainability. So there is a balancing act.
-- Mike W
Roedy Green - 24 Feb 2006 20:36 GMT >Volume of code does IMHO reduce maintainability, that is without considering >other factors. Of course good names improve maintainability. So there is a >balancing act. with Eclipse and Intellij when you write code you can use short names, then run down the list when you are done with a global rename to pick names that can't be misunderstood.
With the right names, even the most hairy code suddenly makes sense.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 19 Feb 2006 02:04 GMT >this class I named, "GameGroup," though I suppose I >could have just called it, "Games." a gazebo of games. See http://mindprod.com/jgloss/collectivenouns.html
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Raymond DeCampo - 20 Feb 2006 18:00 GMT >>this class I named, "GameGroup," though I suppose I >>could have just called it, "Games." > > a gazebo of games. See > http://mindprod.com/jgloss/collectivenouns.html A gazebo of games? Where did you find that? It is not supported by dictionary.com:
http://dictionary.reference.com/search?q=gazebo
Ray
 Signature This signature intentionally left blank.
Chris Uppal - 20 Feb 2006 20:02 GMT > > a gazebo of games. See > > http://mindprod.com/jgloss/collectivenouns.html > > A gazebo of games? Where did you find that? It is not supported by > dictionary.com: I don't know where Roedy got his data from, but one is allowed to make 'em up too.
I particularly liked "a rash of dermatologists" ;-)
Wasn't so impressed with the collective for programmers, though. Everybody[*] knows that the proper collective noun for a group or team of programmers is a "curse".
Unless there are only two of them in which case they are known as a "curly bracket".
-- chris
[*] == me.
Andrew McDonagh - 20 Feb 2006 22:25 GMT >>>a gazebo of games. See >>>http://mindprod.com/jgloss/collectivenouns.html [quoted text clipped - 17 lines] > > [*] == me.
:-) You been taking a funny pill today?
Roedy Green - 24 Feb 2006 20:41 GMT On Mon, 20 Feb 2006 18:00:22 GMT, Raymond DeCampo <nospam@twcny.rr.com> wrote, quoted or indirectly quoted someone who said :
>> http://mindprod.com/jgloss/collectivenouns.html > >A gazebo of games? Where did you find that? It is not supported by >dictionary.com: I collect these things. To find one, you google on well known pairs such as "gaggle geese" plus the word you are interested in. That will bring up venery collections that include your word.
These are all just made up, it is a sort of humour to find an appropriate collective noun.
I have a little database of them and a program to, dedup, sort and format them in order by either singular or plural.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Ranganath Kini - 19 Feb 2006 03:37 GMT Why not simply call it "PersonCollection" or "PersonSet" or "PersonList"
Chris Smith - 19 Feb 2006 03:59 GMT > Why not simply call it "PersonCollection" or "PersonSet" or "PersonList" Or, of course, Collection<Person>, Set<Person>, and List<Person> would be even easier, assuming the current version of Java.
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|