An Interface Type is an opaque value used to reference a specified interface of a component instance.
Interface Types are fully qualified references to an instance of a component. See Components, Interfaces. The actual reference is the opaque values returned when you create an instance of a component using the _createInstance() function and is stored internally as a reference type. See reference data type, _createInstance() function. The component instance must implement the specified interface or an error will occur when the component reference is assigned to an interface type variable. An interface type variable may be used to call any methods defined for that interface or handle events defined for that interface.
It is possible to have a component instance variable which does not have a specified interface by creating the variable with the reference data type, however you cannot access any methods or handle any events with it. See reference data type.
Interface types in UJML
In UJML, an interface type is a reference data type specified using a interface name instead of the keyword 'reference', with the value stored as a component instance in memory. Unlike a pure reference type, an interface type has the ability to access the methods and events of an interface implemented by a component instance. See reference data type, Components, Interfaces. You can assign an interface reference to another variable. See Variables. You can pass an interface type reference as a function argument and return one from a function. You can tell a interface type instance to paint itself using the display-instance element. See display-instance. You can cast a reference variable or another interface type variable to an interface type if the reference is null or if the component instance implements that interface. See Interface Types. But you cannot convert an interface type to a different data type or use it in an expression, other than casting to an interface type. See Expressions. State variables may not be of an interface type.
Casting interface types
The _castInterface() function converts a reference value to a specific interface type. See _castInterface() function.
You can compare two interface type references to see if they refer to the same component instance using the _isSameInstance() function. See _isSameInstance() function.
You can determine if an interface type instance refers to a component that implements a specific interface using the _instanceOf() function. See _instanceOf() function.
Interface types and 'null'
Interface type references may be a special value called 'null'. When a reference is null, it does not refer to any extension instance. It is, essentially, empty. You can test to see if a reference is null by using the _is_null() function. See _is_null() function. You can also assign the literal value 'null' to a reference variable to give the variable the value null.
Reference literals
Because references are an opaque type, there is no such thing as a reference literal except for the value 'null'. See Literals and Constants.
The following example declares a reference variable for the 'ILifeGrid' interface. It is part of the life.ujml sample.
<var name="mGrid" type="ILifeGrid"/>
The following example shows how to create an instance of the 'LifeGrid' component and put it into the reference variable declared above. It is part of the life.ujml sample.
mGrid = _createInstance("LifeGrid");
The following example shows how to cast a reference variable to an interface type. It is part of the things.ujml sample.
thing = _castInterface(ref, "IThing");
The following example tests an interface type variable to see if it is null. It is part of the things.ujml sample.
if (!_is_null(thing))
|
Copyright (c) 2000-2007 UIEvolution, Inc. All rights reserved.
|
|
What do you think about this topic? Send feedback!
|