TA Properties

From Emergent

Jump to: navigation, search

TA (Type Access) Properties are an abstract concept that provides application programmers with a unified way of accessing "property" data of a class without having to know whether that state data is provided via a method or a member. Properties can be used for the following purposes:

  • to define an abstract virtual accessor, which is then implemented differently in different classes
  • to provide a way for the class to make side-effects or notifications if the value of the property is changed
  • to provide "derived" state values, that do not themselves require member state

In terms of implementation at the C++ level, there are only two implementation constructs:

  • members -- data field values
  • methods -- programmatic functions

Each property has a C++ type, that for now must be compatible with Variant, in other words, it must be a basic numeric, bool, float/double, String, Variant, or taBase* type. Things that cannot be properties include: complex embedded objects, and non-taBase pointers.

A property can be read/write, or read-only. A read/write property has a getter and a setter; a read-only property has only a getter. (It is theoretically possible to define write-only properties, but these are generally not that useful -- this paradigm should use a method, not be considered a property.)

Contents

Accessors

An "accessor" is the way in which a property value is obtained or set. The read accessor is called a "getter"; the write accessor is called a "setter".

getter

A getter is either a member of the object, or a const method that returns the type of the property.

setter

A setter is usually a method on the object that accepts a value of the type of the property; this method internally manages changing the state of the object to reflect the property change. A setter can also be a member, but this is rare.

practical combinations

Although there are many theoretical combinations of getter and setter types, the following are generally the only combinations that are used:

  • read/write memb_get meth_set -- this is a "side-effect" type of property
  • read/write meth_get meth_set -- this is a classic "abstract" type of property
  • read-only meth_get -- "abstract" property

Defining properties

There are two ways in which properties are defined:

  • explicitly -- by marking members and/or methods as getters and setters
  • implicitly -- visible members that are not otherwise property accessors, but that are compatible with being a property, are automatically exposed as properties; if the member is marked #READ_ONLY then it will be a read-only property

Property Directives

A property gets the directives and description from the getter. Apart from this, there is no way to set property directives. Directives that apply only to a Method or Memeber (as applicable) will be ignored in property contexts.

Example properties

This section demonstrates how to define the 3 common types of properties:

read/write, using member:

 bool    visible; // #GET_visible
 void    setVisible(bool val); // #SET_visible

read/write, using methods only:

 virtual String GetName() const; // #GET_name
 virtual void SetName(const String& val); // #SET_name

read-only, using method:

 bool    active() const; // #GET_active

Restrictions and Caveats

Only up to one getter and one setter should be defined for a given property name. If you try to say define a member and a method getter, the result is undefined (it will create a compile error when compiling xx_TA.cpp).

The type of the getter and the setter must be the same. The setter can use combinations of "const" and & (ref), ex. "const String&".

Personal tools