Skip to content

Commit

Permalink
Remove new text and add heading to examples as suggested.
Browse files Browse the repository at this point in the history
Also change comment indentation.
  • Loading branch information
HansOlsson committed Nov 25, 2020
1 parent 564f199 commit aff7f58
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions chapters/inheritance.tex
Expand Up @@ -547,6 +547,7 @@ \subsection{Final Element Modification Prevention}\label{final-element-modificat
\end{nonnormative}

\begin{example}
Final component modification.
\begin{lstlisting}[language=modelica]
type Angle =
Real(final quantity = "Angle", final unit = "rad", displayUnit = "deg");
Expand All @@ -569,26 +570,25 @@ \subsection{Final Element Modification Prevention}\label{final-element-modificat
end Test;
\end{lstlisting}
\end{example}
Declaring a class final makes all of its elements final, and makes the class non-replaceable.
This definition applies recursively to the elements of the class that are also classes.
It follows that a final class can only be used without modification.

\begin{example}
Final class declaration.
\begin{lstlisting}[language=modelica]
model Test2
final model MyTF = TransferFunction(b = {1, 2});
/* Equivalently:
final model MyTF = TransferFunction(final a, final b = {1, 2});
*/
MyTF tf1; // fine
MyTF tf2(a = {1, 2}); // error, all elements in MyTF are final
model M = MyTF(a = {4}); // error, all elements in MyTF are final
MyTF tf1; // fine
MyTF tf2(a = {1, 2}); // error, all elements in MyTF are final
model M = MyTF(a = {4}); // error, all elements in MyTF are final
model TFX
extends MyTF; // fine
extends MyTF; // fine
Real foo = 1.0;
end TFX;
TFX tfx(foo = 2.0); // fine, foo is not from MyRF
TFX tfx2(a = {1, 3}); // error, all elements from MyTF are final
model TFX3 = TFX(a = {1, 4}); // error, all elements from MyTF are final
TFX tfx(foo = 2.0); // fine, foo is not from MyRF
TFX tfx2(a = {1, 3}); // error, all elements from MyTF are final
model TFX3 = TFX(a = {1, 4}); // error, all elements from MyTF are final
end Test2;
\end{lstlisting}
\end{example}
Expand Down

0 comments on commit aff7f58

Please sign in to comment.