Composite1 data items that represent principal objects of the application domain are called entities2. Many kinds of entity have one or both of these attributes:
In OOP, we can and often should define types for all three, i.e. the entity itself, the entity name, and the entity identifier.
To avoid confusion, we need to assign type names that make it absolutely clear which kind of thing we're dealing with. Here's one set of naming standards.
City, Company,
Course.
Name
or Title to the entity type name, e.g.
CityName, CompanyName, CourseTitle.
StateCode, CourseID. Altenatively
where an industry standard name is in common use, it can be substituted,
e.g. ISBN instead of BookID.
typedef can be used.
enum can be used.
Any accessor functions in the complete entity class that yield
the name or identifier must return a value of that type.
For example:
Class City {
CityName name_;
public:
A common mistake among newcomers to OOP is to ignore the name and
identifier classes and expose their internal represntation. For example
the following, although rather common even in textbooks, seriously violates
encapsulation:
Class City {
String name_;
public:
String name() const // NO!!
{return name_;}
.
};
This issue is discussed in more detail in Pseudo-classes and Quasi-classes Confuse Object-Oriented Programming. Naturally the name and identifier classes must support sufficient functionality to render such violations unnecessary. Typically that functionality includes:
Implmenting these related types in Java follows the C++ model with just two exceptions:
typedef and enum options
don't exist. All three types have to be defined as classes.
1 As contrasted with elementary or container types, as explained in Data-item Taxonomy and Object-Oriented Class Definition.
2 The OOA community sometimes calls them business objects. Coad & Yourdon call them subjects
Return to Technical articles
Return to IDI home page.