I’m looking a name for a class in the system which has Id (Long) and Name (String) in a java environment.
Are their any conventions for this kind of class, or is it just architecture related?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ve seen some places where names such as
IdAndNamehave been used. I don’t like it. Such names are too coupled with the current status of the class. It is quite likely that new feeds will be added to/removed from this class and then the name will stop being accurate.So, I would encourage you to think along both of these directions:
What is this class representing? If this is the superclass of all “things” that have an “ID” and a “Name” then you can call it
NamedEntity(the termEntityis quite common for describing persistent objects that maintain a distinct identity).(Alternatively) do you really want to make it a superclass that many other classes extend? Sounds as if you can move to a design were your entities will hold such an object in a field (as opposed to inheriting from its class). You can then introduce a
Nameableinterface which will define agetId()andgetName()and have these entities implement these methods (cost in term of volume of code is marginal). This will give you better separation of concerns, less coupling (inheritance is the strongest form of coupling) and will not exploit theextendscard which you can play only once.