/
ColdC/Functions/
ColdC/Structure/
<head><title>ColdC: Object Oriented Programming</title></head>

<body>
<h1 align=center><a href="/ColdC/">ColdC</a>: Object Oriented Programming</h1>
<hr>
<p>Object Oriented Programming (OOP) is a style of programming which not
only groups procedures and data by functionality but which also applies a
few common rules to how this grouping occurs.  In OOP designers group
procedures and data into <i>modules</i>.  By doing this it helps to
define the purpose of the program, and also gives the added benefit of
portability (porting a modular segment of code to another program is
much easier than porting an integrated segment of code).</p>

<p>These modules (or <i>objects</i>) will generally follow a few guidelines:</p>

    <ol>
      <li>Abstraction and Encapsulation of Data
      <li>Inheritance
    </ol>

<p>Because data and procedures are grouped together, all procedures which
handle the specific data should be included within the module.  
<a name="encap"><b>Abstraction and Encapsulation</b></a> occurs when
the module abstracts and controls access to the data it manipulates.  The
internal representation of data used by a module is most likely irrelevant
to external sources (with the interface being the primary concern).</p>

<p>An example of <i>Abstraction and Encapsulation</i> would be a table of
people and their pets.  The 'People and Pets' module has several procedures:
</p>

<dl>
  <dt><i>Add Person</i>
    <dd>Add a Person to the table.  This procedure is passed the person,
        and their pet.
  <dt><i>Remove Person</i>
    <dd>Remove a Person from the table.  This procedure is passed the person
        to be removed.
  <dt><i>Get Pet</i>
    <dd>This procedure finds the pet for a given person.  It is passed the
        person and returns the Pet associated with that person.
</dl>

<p>In the People and Pets module the table can be internalized in any form.
The form is irrelevant to external programs which may use it.</p>

<p><a name="inher"><b>Inheritance</b></a> is the ability of another module
to take on the functionality an existing module and further expand upon it.
For instance, a 'People, Pets and their Names' module could be created
which takes on the functionality of 'People and Pets', but expands it to
include the names of the pets.</p>

<p>Inheritance is extremely useful because code becomes reusable and
extendable without having to re-create each portion or module for different
functionality.</p>

<p>In inheritance a module taking on the functionality of another object
is called <i>deriving</i> from that object.  For instance, 'People, Pets and
their Names' is derived from 'People and Pets'.  The module 'People, Pets
and their Names' is a <i>child</i> of 'People and Pets', with 'People and Pets'
being the <i>parent</i> of 'People, Pets and their Names'.</p>

<hr size=4><p align=center><i>Last Modified on Jan 25 1996</i>
<br><i>Copyright &copy; 1995, 1996, Brandon Gillespie</i>
</body>