开发者

Is it bad practice to use the namespace to identify the verb or should it always be in the class name?

开发者 https://www.devze.com 2022-12-24 06:23 出处:网络
For example is 开发者_如何学C MyLibrary.Data.Import.Hotels Bad Vs MyLibrary.Data.Import.ImportHotels

For example is

开发者_如何学C
MyLibrary.Data.Import.Hotels

Bad Vs

MyLibrary.Data.Import.ImportHotels

Or even

MyLibrary.Data.ImportHotels


IMO!:

Verb should be used only on method names. Classes names should be nouns. Same for namespaces. My version MyLibrary.Data.Hotel.Import() or something like this


As Andrey pointed out, class names are describing classes of objects.

The instances of that class are the objects themselves, e.g. the class is Hotel and an instance of that class could be an object for "The Ritz".

Some nouns can further be used to add attributes of the object, e.g. number of rooms, hotel name, number of vacant rooms, etc.

Verbs are then used to describe actions upon the object instance or attributes, e,g. setNumberOfRooms, getNumberOfVacantRooms, etc.

How could you say a verb is an object? Just looking at your object heirarchy's raises a bit of a smell. In the refactoring sense of course! (-:

For further information, I can't recommend the book "Object Oriented Systems Analysis: Modeling the World in Data" highly enough. It's from the early days of OOA but still highly relevant today.

HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号