| Contents | Index |
Subclassing allows you to build component models based on other component models by extension. Subclassing applies only to component models, not domain models. The syntax for subclassing is based on the MATLAB class system syntax for subclassing using the < symbol on the declaration line of the component model:
component MyExtendedComponent < PackageName.MyBaseComponent % component implementation here end
By subclassing, the subclass inherits all of the members (parameters, variables, nodes, inputs and outputs) from the base class and can add members of its own. When using the subclass as an external client, all public members of the base class are available. All public and protected members of the base class are available to the setup and equation functions of the subclass. The subclass may not declare a member with the same identifier as a public or protected member of the base class.
The setup function of the base class is executed before the setup function of the subclass. The equations of both the subclass and the base class are included in the overall system of equations.
For example, you can create the base class ElectricalBranch.ssc, which defines an electrical branch with positive and negative external nodes, initial current and voltage:
component ElectricalBranch
nodes
p = foundation.electrical.electrical;
n = foundation.electrical.electrical;
end
variables
i = { 0, 'A' };
v = { 0, 'V' };
end
function setup
across( v, p.v, n.v );
through( i, p.i, n.i );
end
end
If, for example, your base class resides in a package named +MyElectrical, then you can define the subclass component Capacitor.ssc as follows:
component Capacitor < MyElectrical.ElectricalBranch
% Ideal Capacitor
parameters
c = { 1, 'F' };
end
function setup
if c <= 0
error( 'Capacitance must be greater than zero' );
end
end
equations
i == c * v.der;
end
end
The subclass component inherits the p and n nodes, as well as the i and v variables with initial values, from the base class. This way, the Capacitor.ssc file contains only parameters, setup, and equations specific to the capacitor.
![]() | Attribute Lists | Simscape File Deployment | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |