2

I just stumbled over an interesting problem with naming.

I am writing automated tests for an Object-Relational mapper.

This involves using super-generic classes that exist solely to exercise certain relationships.

My test first involved composition: One object held another object which held a collection of objects:

Entity => ParentComponent => Bag => ChildComponent.

This naming seemed to make sense - one parent had many children.

But then I wanted to expand my tests for a class that inherits from Entity. I instinctively named it ChildEntity

 Entity => ParentComponent => Bag => ChildComponent 
 ^
 |
ChildEntity

This now gets confusing! I'm using Parent/Child labeling to denote inheritance, and I'm also using Parent/Child labeling to denote composition.

Is there some standard labeling nomenclature I can use that differentiates between the two relationship types?

asked Feb 25, 2017 at 22:57

3 Answers 3

3

Child is wrong in an inheritence context because it says nothing about the type. If you would model a cat you would not name the class AnimalChild.

When you talk about OO and explain the concept or the place of a class in its inheritence tree you may speak of child. When you name the class the name should convey its purpose.

answered Feb 26, 2017 at 12:04
1
  • But you would name a child derived from a cat simply kitten which is derived from kitonwhich is a deminutive of cat which connotates the parent-child-relationship ;) But you are totally right: simply suffixing something with child is not really helpful. Commented Feb 26, 2017 at 16:37
2

According to this guy, when using composition, the container class is called a "front-end class" while the classes being contained are "back-end classes."

With regards to inheritance, I don't think parent/child is common, nor is it correct (a parent and child in the real world would be the same type of organism). More common for inheritance are the terms ancestor/descendant, supertype/subtype, or superclass/subclass. Subclass is also commonly used as a verb, as in "to make it do X, subclass it and override Y."

answered Feb 26, 2017 at 8:01
1

In composition, we quite often discuss the issue of "ownership" and the composition relation is quite often named a "has a" relation. So, I believe it would be quite descriptive to name the object Owner/Owned (I am not very happy about the owned part, but I could not find something better for the object owned by the owner).

answered Feb 25, 2017 at 23:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.