Purpose | The node statement is used to instantiate (i.e. create) an object. The object will exist in the run-time memory once it is instantiated. | |
Format |
node({parent classes}) {object name}({constructor parms}) {nocode} {noconstruct} { child nodes }; node {object name}; node {object name} {nocode} { child nodes } | |
{parent classes} | (optional) a comma-separated list of the names of the parent classes to be inherited from. If no class names are present then the object is instantiated as an instance of the Node class. | |
{object name} | the name of the object being instantiated | |
{constructor parms} | (optional) a comma-separated list of the named parameters and their values for the constructor method | |
{nocode} | (optional) if present it specifies that Superx++ statements enclosed in the {child nodes} of the node statement are to be processed before being embedded in the object. If omited then they are not. | |
{noconstruct} | (optional) if present it specifies that the constructor method and the construct clause will be executed for the object. | |
{child nodes} | (optional) the nodes to be instantiated as descendants of the object. These nodes are not the same as those derived from the inheritance via the class attribute. These nodes represent customizations in the instantiation of individual objects of a class. This phenomenon is called customized instantiation and is useful in modeling exceptional cases that evolve in real life or real systems. | |
Example #1 |
node MyNode; The node statement instantiates an object of class Node whose name is MyNode which contains nothing. | |
Example #2 |
node MyNode {Hello World!}; The node statement instantiates an object of class Node whose name is MyNode which contains the value Hello World!. |
|
Example #3 |
node MyNode { <MyChild class="XObj" construct="false" status="new" var_int_d="2" arr_string_x.3.="{cat,dog,mouse}"> Inside </MyChild> }; The node statement instantiates an object of class Node whose name is MyNode which contains another object. The contained object is called MyChild and contains a value, Inside, an attribute called status whose value is new, a integer variable called d whose value is 2 and a string array with 3 elements called x whose elements' values are cat, dog and mouse respectively. |
|
Example #4 |
node(XPlant) MyTree; The node statement instantiates an object of class XPlant whose name is MyTree which contains only the inherited members and methods of the XPlant class. This is an example of single inheritance. |
|
Example #5 |
node(XPlant,XLargeObject) MyTree; The node statement instantiates an object of classes XPlant and XLargeObject whose name is MyTree which contains only the inherited members and methods of the XPlant and XLargeObject classes. This is an example of multiple inheritance. |
|
Example #6 |
node(XPlant,XLargeObject) MyTree { <MyChild class="XObj" construct="false" status="new" var_int_d="2" arr_string_x.3.="{cat,dog,mouse}"> Inside </MyChild> }; The node statement instantiates an object of classes XPlant and XLargeObject whose name is MyTree which inherits members and methods from the XPlant and XLargeObject classes. In addition, the MyTree object contains the MyChild object. This example illustrates multiple inheritance and customized instantiation. |
|
Example #7 |
node(XPlant,XLargeObject) MyTree { <MyChild> getxout </MyChild> }; The node statement instantiates an object of classes XPlant and XLargeObject whose name is MyTree which inherits members and methods from the XPlant and XLargeObject classes. In addition, the MyTree object contains the MyChild object which in turn contains the contents of the output stream. This example illustrates multiple inheritance and customized instantiation while showing the utility of the processcode attribute. |
|
Example #8 |
node(XPlant,XLargeObject) MyTree nocode { <MyChild> getxout </MyChild> }; The node statement instantiates an object of classes XPlant and XLargeObject whose name is MyTree which inherits members and methods from the XPlant and XLargeObject classes. In addition, the MyTree object contains the MyChild object which in turn contains the <getxout> statement as a child node. This example illustrates multiple inheritance and customized instantiation while showing the utility of the processcode attribute. |
|
Example #9 |
node(XPlant) MyTree; The node statement instantiates an object of class XPlant whose name is MyTree which contains only the inherited members and methods of the XPlant class. The constructor method and the <construct> clauses of the XPlant class are executed. |
|
Example #10 |
node(XPlant) MyTree noconstruct; The node statement instantiates an object of class XPlant whose name is MyTree which contains only the inherited members and methods of the XPlant class. There is no execution of either the constructor method or the <construct> clauses of the XPlant class. |