company logo

Typed property handle

So far, generic database access has been discussed. In contrast to generic property handles, types property handles provide direct access to instance data in the context of a C++ class definition. Typed property handles are supported via template classes. Instead of referring to the selected instance in the property node, the application may directly refer to instance properties returned by the template class.

When using typed property handles, the system will not be informed about instance modifications and the application program has to signal updates explicitly. Moreover, no data conversion will be performed and has to be managed by the application program as well.

Another disadvantage is, that you must not define virtual functions for types used in typed property handles, since the ODABA instance factory does not create virtual function vectors.

Hence, we suggest always using generic property handles rather than typed property handles.

// using typed Property Handles

  PI<Person>        persons(obh, "Person::Persons", PI_Write");

  

  while ( persons.Next() )

    if ( persons.Get()->UpdateAge() )

      persons.Modify();

// Update function as implemented in the Person Class

bool Person::UpdateAge() {

  int        old_age;

  dbdt       current;

  current.SetDate();

  age = birth_date.Year() - current_year;

  return ( age != old_age);

}

// using generic property handles with update control

  Property    persons(os, "Person", PI_Write");

  Property    birth_date(&persons, "birth_date");

  Property    age(&persons, "age");

  Date        current;

  int         year = current.setDate().Year();

  

  while ( persons.Next() )

    age = year - birth_date.GetDate().Year();