Modeling Services > Relations > One-to-one Relations > Defining Ownership Relations
 
Defining Ownership Relations
Let us suppose that we want to define a relation between an object of type Person and an object of type Car, such as a person owns a car. To do so, we would declare a data member car of type IlsOwns inside the class defining the owner object, that is the class Person, as follows:
class Person:
public IlsObject
{
public:
  IlsOwns<Person,Car> car;
  Person();
};
A class that declares a Server relation must derive publicly and directly or transitively from the class IlsObject or IlsEntity. A class whose instance is the origin of a relation of type IlsOwnsPerson in the example—can derive from the class IlsObject or IlsEntity directly or transitively. Derivation must be public.
The target class, on the other hand, must exclusively derive from IlsObject, since an entity cannot be owned. For details about basic objects versus entities, see Basic Features.
Note:  To simplify the code in the examples used in this manual, relations are usually declared in the public section of classes. However, they could also be defined in the private section, as shown in the code extract directly below.
class Person:
public IlsObject
{
public:
   Person();
   CarP getCar(){return car;}
   void setCar(CarP aCar){car=aCar;}
private:
   IlsOwns<Person,Car> car;
};

Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.