You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Polymorphism allows us to process objects differently depending on their data type or class.
626
+
Based on type compatibility and equivalence, three type systems can be determined:
627
+
\begin{itemize}
628
+
\item\textbf{Nominal type system}: The compatibility and equivalence of data types is is determined by explicit declarations or name.
629
+
Example: C++, C\#, Java.
630
+
\item\textbf{Structural type system}: The compatibility and equivalence of data types is is determined by their structures or definitions: if they have the same definition then they are equivalent.
631
+
Example: OCaml, Scala, Go.
632
+
\item\textbf{Duck typing}: The compatibility is determined by the presence of certain methods and fields.
633
+
``\textit{If it walks like a duck and talks like a duck, it must be a duck}".
634
+
Example: Javascript, Python, Ruby.
635
+
\end{itemize}
636
+
637
+
Table~\ref{tab-polymorphism} represents a comparison between some OOP languages based on their polymorphism capacities:
638
+
\begin{itemize}
639
+
\item\textbf{Type compatibility}: Nominal, structural or duck.
640
+
\item\textbf{Get object type}: How to get the type of a given object.
641
+
\item\textbf{Is instance of}: Verify if an object is generated from a class/prototype.
642
+
\item\textbf{Members existence}: Check if a member (field or method) exists in a given object.
643
+
\item\textbf{Type casts}: Downcasting is the act of changing a reference of a base class to one of its derived class.
644
+
\item\textbf{Overloading}: Having methods overloading or not.
645
+
\end{itemize}
646
+
As for overriding, no need to compare since all of our languages afford this property.
0 commit comments