About Creating a Class

This section provides an overview of your options for creating a new class. An important issue is the starting point when creating a new class.

This page discusses:

Class Creation Using New Class Command

The command New Class can be used:

  • To create an empty new class.
  • To extend from an existing class. Extending a class allows you to reuse an existing class with inheritance. For example, you can create a new class from an existing one and add more objects. This new class inherits any modification from the original class that it was extended from.
    Note: We advice not to use copy/paste. If you want to create a new class from an existing class without extending, use the context command Duplicate Class. For more information, see Duplicating a Class.

In both cases, the new class can be made partial. A partial class works as a template: a component created from such a class is replaceable.

See Create a New Class or Extend from an Existing Class Using the New Class Command.

Class Creation from a Replaceable Component

A new class can be created using the context menu of a replaceable component to extend its constraining clause class.

This can be seen as a specific case of the above option, where the class to extend is selected first (via the replaceable component) rather that the creation command is selected first.

Note: The class that is extended is the constraining clause class, which might not be the same as the class of the component.

See Extend from a Replaceable Component.

Class Creation by Model Split

The command Split Model can be used to create new classes in several ways.

You can:

  • Create a submodel from selected objects
  • Create a base class from selected objects
  • Create a model and copy the selected objects to that model

The starting point here is a class (often a model) containing components. Compared to creating an empty class (using the New Class command), this can be seen as creating a class from a selection of objects (even a single object).

Submodels are useful to group components in a complex model, making the model easier to understand. The grouped components (and related parameters and connections, if so selected), are moved to a new class. That class is then instantiated to replace the components in the original class. Connections to the outside of that component are restored. (Connectors are automatically added in the submodel.) Submodels can be made public for reuse, and inserted in other classes than the original class. Submodels are always of class type model.

Base classes are useful to reuse classes. The grouped components (and related parameters and connections, if so selected), are moved to a new base class. That class is extended by an extends clause into the original class. Connections to the components of the original class are restored. Base classes created this way can only be created as public. They can be inserted in other packages than the original one. They can also be made partial. Base classes inherit the type of the selected components.

Copy to a new model leaves the selected objects and the enclosing class untouched; the selected objects are copied to a new model. This is useful when you want to use the selected objects as a starting point rather than for resuse. The new model can be made partial.

Important:
  • Creating a submodel changes the diagram layer: the submodel is represented by a new component in the diagram layer. To display the components of the submodel, open this component.
  • Creating a base class does not change the diagram layer.
  • Copying to a model leaves no linking to the original components.

To split a model, see Splitting a Model.