开发者

Choosing informative class names

I'm having a hard time coming up with informative and useful class names. One class I am have this problem with makes requests to websites/servers. I thought it would only be fitting to name this class ServerRequest which is within the package of ServerServices. This p开发者_如何学JAVAackage also contains the classes ServerData and ServerImage. ServerData parses the response from ServerRequest and creates objects. ServerImage will copy remote images to local machine using ServerRequest.

I don't feel like it's good practice to prefix every class name. At the same time I don't want to simply name the classes Request, Data, and Image. Without the prefix the names lose their meaning, not to mention how common they become.

What are good conventions to use, beyond CamelCase and using nouns?

What are some examples of class names to use for the three classes above?


Well if you're going to have ServerData, MailData, UserData then the prefix is certainly a good idea to know which Data we're talking about. But if class-name confusion isn't a problem (also depends on the scale of the project...) you could regroup all your classes under the something.here.server package and keep simple class names like Request, Data and Image.

It's all about aiming for maximum readability and code clarity.


It sounds like you have a ServerClient that returns a ServerResponse, which is in turn parsed by a ServerResponseParser into a ServerData. I'm not quite clear on the "image" part. Would it be an ImageRequester which uses ServerClient to get ServerImages?


In my opinion the Classname needs to express what Data is saved/parsed/requested, the Packagename groups a subset of functionality of your application.

So we have a UserImage in package user.data.roster for example, so everything that has todo with showing a roster of the users goes there.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜