References and Reference Properties

Let’s learn about references and reference properties.

We'll cover the following

References

A reference can be either a human-readable or internal object reference. Human-readable references refer to identifiers used in human communication, such as the unique names of astronomical bodies, the ISBN number of books, or the employee identification numbers of a company. Internal object references refer to the computer memory addresses of OOP objects, providing an efficient mechanism to access objects in the main memory of a computer.

Some languages, like SQL and XML, only support human-readable references—not internal ones. In SQL, human-readable references are called foreign keys. The identifiers that the foreign keys refer to are called primary keys. In XML, human-readable references are called ID references. The corresponding attribute type in XML is IDREF.

Objects in an OO program can be referenced either with the help of human-readable references (such as integer codes) or with internal object references. Internal object references are preferable for accessing objects efficiently in the main memory. Following XML terminology, we call human-readable references ID references and follow the standard naming convention for ID reference properties. An ID reference property defined in class A that references objects of class B has the name b_id and uses the suffix _id. When we store persistent objects in the form of records or table rows, we need to convert internal object references that are stored in properties like publisher into ID references that are stored in properties like publisher_id. This conversion is performed as part of the serialization of the object by assigning the standard identifier value of the referenced object to the ID reference property of the referencing object.

Reference properties

In OO languages, a property is defined for an object type or class, which is known as its domain. The values of a property are either data values from some datatype, in which case the property is called an attribute, or they’re object references that reference an object from some class, in which case, the property is called a reference property. For instance, the class Committee shown below has a name attribute with the range String and a chair reference property with the range ClubMember.

Get hands-on with 1400+ tech skills courses.