Creating Instances

1 Point

The declaration of a class starts with a keyword, class for instance, followed by the name of the class. A class declaration creates a type name which makes it possible to declare variables of that type, also known as an instance of the class, simply by writing: typename variable. First we declare the class Point., where the variables x, y and z are instances of the type Real.



2 MyPoints

To create new instances the "new" keyword is not used as is common in object-oriented programming languages, since it does not exist in Modelica. In MyPoints three instances of Point are created. Point1 is created with initial values for the variables, given through modification.



3 Look at Flattened Version of MyPoints


4 Instances of MyPoints

MyPointsInst creates three new Points by instantiating MyPoints. There are two different ways to give the variables initial values when creating the instance. This is shown in MyPointsInst1 and MyPointsInst2.




5 Simulation of MyPointsInst1 and MyPointsInst2