next up previous contents
Next: Category as Container Class Up: Categories Previous: Categories

Function vs. Object Oriented

In a functional language, a three dimensional vector of reals (three-vector for short) could be a data structure holding three real numbers $(x\ y\ z)$ and a collection of functions operating on vectors ( $(function1)\ (function2)\ \ldots$). In an object oriented programming environment one might define a three-vector class, combining the coordinates (the member data) with the vector functions (the member methods), e.g. $(x\ y\ z\ (\mathit{method1}){}(\mathit{method2})\ \ldots )$. The main advantages of the object oreinted approach are data abstraction, encapsulation, and inheritance. However, object orientation imposes certain limitiations. For instance, when dealing with large numbers of instances, an array of records,

\begin{displaymath}\left((x_1\ y_1\ z_1)\ (x_2\ y_2\ z_2)\ \ldots \right),
\end{displaymath} (1.1)

may be significantly more compact than the coresponding array of objects, especially if a function table is present:

\begin{displaymath}\left((x_1\ y_1\ z_1\ (\mathit{method1}_1)\ (\mathit{method2}...
...{method1}_1)\ (\mathit{method2}_1)\ \ldots)
\ \ldots \right).
\end{displaymath} (1.2)

More importantly, the data-procedure encapsulation present in object instances may make it slower to manipulate objects than a corresponding collection of records1.5. If many operations of this type are performed (such as translating or rotating every vector in an array) the overhead can be significant.


next up previous contents
Next: Category as Container Class Up: Categories Previous: Categories
Richard W. DeVaul
1998-12-07