Composite
See Also: Class
Purpose
Allows for the creation of compositions of multiple objects.
Syntax
Composite {composite-class} Is A {super-class}
:
End_Class
Where:
- {composite-class} is the name of the new class to create.
- {super-class} is the name of the class that the new class is based upon.
- {composite-class} may be between 1 and 4096 characters in length, must start with a letter, and may not contain spaces. Recommended characters are 0-9, a-z, A-Z, and _ (underscore).
What It Does
The Composite Class is a new object-oriented class type that allows for creating compositions of multiple objects. This means that a Composite can be instantiated like a Class, but the scope in-between Composite and End_Composite is written like an Object. This allows for nested objects and procedures, making it very comparable to an instantiable template.
This new class type was initially added to help with the instantiation of multiple objects as a single component, such as a cWebWidget, but can be used in many ways. The Composite is also very useful when dealing with complex Dynamic Objects, as the framework will automatically pick up on the nested objects.
Example
Composite cWidgetAction is a cWebWidget
Set psWidgetCaption to "Action"
Set psWidgetDescription to "Perform a navigation operation"
Set psWidgetName to "WidgetAction"
Object oActionBtn is a cWebButton
Set psCaption to "Customer Query"
Set pbFillHeight to True
Procedure OnClick
Send PerformAction
End_Procedure
End_Object
…
End_Composite
Object oWidgetInstantiation is a cWidgetAction
Set psWidgetCaption to "Custom Value"
End_Object
Like with a Class, a Composite is based on a base class. It is possible to inherit from another Composite, but it was not specifically designed for that use case.
As stated, Composites are, in essence, Classes, which means that you can create them as Objects with a Composite as a base class or using the Create function in the following manner:
Composite cCustomClass is a cObject
Object oChildObject1 is a cObject
End_Object
Object oChildObject2 is a cObject
End_Object
End_Composite
Handle hoObj
Get Create (RefClass(cCustomClass)) to hoObj
As can be seen in the image below, after the create statement, the specified child objects of the Composite are created. This is because at the moment of creation, the scope in between the Composite and End_Composite is executed.
