Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming classes like "com.facebook.FacebookClient" vs "com.facebook.Client"

I'm looking for opinions or if there is an agreed way of doing this, regarding to naming namespaced classes.

E.g.:

com.facebook.FacebookClient
vs
com.facebook.Client

Or

javax.script.ScriptEngine;
vs
javax.script.Engine;

I'm currently prefer the first name in each example but the extra word seems a bit wasteful.

like image 929
Amy B Avatar asked Jan 22 '23 23:01

Amy B


2 Answers

Using Actionscript as an example, I'd say FacebookClient over Client. For this reason:

import com.facebook.Client;
import com.twitter.Client;

You'd have to refer to the class by it's full package to create an instance in the same class:

new com.facebook.Client();

If it was FacebookClient, I could have both

new FacebookClient();
new TwitterClient();

Plus Client would be annoying to me when code completion pops up. An extra click to select the correct Client ;)

like image 129
typeoneerror Avatar answered Mar 30 '23 01:03

typeoneerror


I generally go with something like:

[company name].[project name].[functional area].[category]

i.e.

com.dave.megaproject.dataaccesslayer.postcodelookup

or in the .net world:

namespace DaveFirm.MegaProject.DataAccessLayer.PostCodeLookup

like image 28
DaveRead Avatar answered Mar 30 '23 01:03

DaveRead