Singular and Plural Classes - conventions

V

VisionSet

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...
 
M

Michael Redlich

VisionSet said:
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.
 
C

Chris Uppal

VisionSet said:
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
 
R

Raymond DeCampo

Chris said:
VisionSet wrote:




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.

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
 
E

Ed

VisionSet said:
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...

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
 
V

VisionSet

Ed said:
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.
 
A

Andrew McDonagh

VisionSet said:
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
 
C

Chris Smith

Ranganath Kini said:
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.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
M

Mike Schilling

Andrew McDonagh said:
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.
 
A

Andrew McDonagh

Mike said:
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.

lmao

brilliant!
 
V

VisionSet

lmao

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.
 
C

Chris Uppal

Raymond said:
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.
 
A

Andrew McDonagh

Chris said:
Raymond DeCampo wrote:

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.

:)

You been taking a funny pill today?
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top