Naming Conventions

Naming Conventions

Old forum URL: forums.lhotka.net/forums/t/365.aspx


Michael Hildner posted on Tuesday, June 13, 2006

Hello,

Does anyone have any business object naming conventions they'd like to share?

My project is going to have lots of business objects, and I'm starting to struggle with how I should name them. Right now I've got classes like "PrintItemEditableRootWithChildren", "PrintItemReadOnlyRootList" and "PrintItemReadOnlyChild" etc. I know it's time to standardize things when I start renaming my classes over and over.

Thanks,

Mike

hurcane replied on Tuesday, June 13, 2006

I, too, struggle with naming objects. I have the same problem with database table names and column names. I tend to obsess over it a little too much because I'm a perfectionist.

I would question whether you really need modifiers like "ReadOnlyRootList", "EditableRootWithChildren", etc. Given your examples, I might have object names PrintItem, PrintItemsInfo, PrintItemChildInfo.

That last one has me a little confused. What is the point of a read-only child? I would think all read-only objects are treated as root objects. Same for read-only lists.

In general, I put "Info" on the end of read-only objects. Lists use a plural. Children are concatenated, and lead to somewhat longer names. But the names relate directly to the object, and not its technical state. Here's a somewhat complex set of object names I've used:

Editable objects and lists:
CatalogItem (item in a product catalog)
Warehouse (a physical location)
WarehouseBins (a list of sub-locations in a warehouse)
WarehouseBin (a sub-location in a warehouse)
WarehouseItem (a catalog item in a warehouse)
WarehouseItemBins (a collection of warehouse bins for a warehouse item)
WarehouseItemBin (I hope you're getting the idea...)

Theoretically, I could have a WarehouseItems object, but we don't have any use cases that call for it.

I have lots of read-only objects. A couple examples.
WarehouseItemBinsInfo
EmptyWarehouseBinsInfo
WarehouseItemInfo

I don't know if this kind of standard appeals to you, but it hasn't caused too much confusion with our team.

Michael Hildner replied on Tuesday, June 13, 2006

Hi hurcane,

I know what you mean when trying to name DB stuff, I've used different conventions there and I guess it's ok if you know the convention. Still, I struggle.

When it comes to CSLA business objects, I'm not so sure. This is no doubt related to that I use CodeSmith and those templates, and there are different names (templates) for the same base CSLA type. I've noticed that some classes that derive from the same type have more methods than the other, and I'm in the process of trying to figure out each one's purpose (I'm new to both CSLA and CodeSmith).

Regardless, I can see where I might have a PrintItem, which is an editable root, and a PrintItem, which is a read-only root, so I can't name both classes "PrintItem".

I just thought I'd ask if someone has an "official" naming convention instead of creating my own. By "official" I just mean something that has worked ok in a multi-developer environment.

Thanks,

Mike

hurcane replied on Tuesday, June 13, 2006

Michael Hildner:

Regardless, I can see where I might have a PrintItem, which is an editable root, and a PrintItem, which is a read-only root, so I can't name both classes "PrintItem".



With the convention I described, the editable PrintItem is called "PrintItem". The read-only PrintItem is called "PrintItemInfo".

DancesWithBamboo replied on Wednesday, June 14, 2006

Classes that are lists I always put List at the end.  Then I use a plural suffix like: "WidgetList _Widgets = WidgetList.NewList".

Another idea that I have used before is to use namespaces to seperate objects like: "Company.Product.SubSection.View.Widget" and "Company.Product.SubSection.Edit.Widget.

DavidDilworth replied on Wednesday, June 14, 2006

There's no right answer with this, so whatever works best for you is the right answer.

For what it's worth, currently we're using a convention very similar to the one described by DancesWithBamboo.

We use namespaces to differentiate between editable and read-only objects.  And we use the suffix List to mean collections of items.

So for example,

Company.Product.Business.Person
Company.Product.Business.PersonList
Company.Product.Business.ReadOnly.Person
Company.Product.Business.ReadOnly.PersonList

HTH

Michael Hildner replied on Wednesday, June 14, 2006

Thanks all for the replies. I realize there's no definitive answer as it's just a naming convention, I was just fishing for ideas.

hurcane, I guess the email I got on your initial reply didn't have all the info - that is I didn't see your listing when I replied to that. You were clear on your first post, thanks.

Regards,

Mike

Copyright (c) Marimer LLC