Skip to content

Commit

Permalink
Clarify final for classes. (#2719)
Browse files Browse the repository at this point in the history
* Clarify final for classes.
Closes #2676
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
  • Loading branch information
HansOlsson committed Nov 25, 2020
1 parent 8f30d5c commit e960bef
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions chapters/inheritance.tex
Original file line number Diff line number Diff line change
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 @@ -570,6 +571,28 @@ \subsection{Final Element Modification Prevention}\label{final-element-modificat
\end{lstlisting}
\end{example}

\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
model TFX
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
end Test2;
\end{lstlisting}
\end{example}

\section{Redeclaration}\label{redeclaration}

A \lstinline!redeclare! construct in a modifier replaces the declaration of a local class or component with another declaration. A \lstinline!redeclare! construct as an element replaces the declaration of a local class or component with another declaration. Both \lstinline!redeclare! constructs work in the same way. The \lstinline!redeclare! construct as an element requires that the element is inherited, and cannot be combined with a modifier of the same element in the extends-clause. For modifiers the redeclare of classes uses a special short-class-definition construct; that is a subset of normal class definitions and semantically behave as the corresponding class-definition.
Expand Down

0 comments on commit e960bef

Please sign in to comment.