comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: Example of object oriented Ada95 requested!
Date: 1996/01/08
Date: 1996-01-08T00:00:00+00:00	[thread overview]
Message-ID: <4cr0ol$ojr@newsbf02.news.aol.com> (raw)
In-Reply-To: slrn4eumdg.4d.cabal@TerpTavern.umd.edu

Arcadio A Sincero (cabal@TerpTavern.umd.edu) is using
Ada-Tutr and asking about examples of encapsulation,
inheritance, and polymorphism.

Dear Arcadio,
     You're absolutely right about the package being Ada's primary
mechanism for encapsulation.  As you get into the tutorial, you'll learn
how packages help contain the effects of changes to one part of the
program; this is even more true when you get into private types.
     The full advantages of inheritance and polymorphism (OOP) don't
really come into play until the project gets pretty large.  In my
tutorial, I try to keep the examples fairly simple.  While I expect the
user to grasp the examples, I only hint at the _advantages_ of OOP. 
Admittedly, I don't really expect the user to grasp the advantages until
he or she has worked with larger projects.
     Inheritance usually (but not always) refers to child packages and
heirarchical libraries.  Sometimes the word inheritance is also used with
derived types, which were available in Ada 83.  For example, if we write
type Count is new Integer; then type Count _inherits_ the operations that
Ada already knows for Integer, such as addition, subtraction, etc.  That
use of the word inheritance has little to do with OOP.  When used with
heirarchical libraries, inheritance refers to the fact that a child
package inherits resources from the parent, and can add additional
resources of its own.  The advantage is that the child package can be
modified and recompiled, without need to recompile the parent and the
program units that "with" only the parent.  On a large project, this can
save not only a lot of recompilation time, but a lot of time spent on
program redevelopment as the requirements are refined or changed.
     Polymorphism (meaning many forms) usually refers to tagged record
types.  The example in the tutorial of tagged type Date (having fields
Day, Month, and Year) and type Complete_Date (adding a day-of-week field
to type Date) is an example of polymorphism.  The advantages include the
fact that we can create heterogeneous linked lists, trees, and other
structures (containing Dates and Complete_Dates), and that we can have the
system decide at run time which of several subprograms to call, depending
on the type of an object, which might be pointed to by an access type. 
This feature is called dynamic dispatching.  Again the advantages show up
in larger projects.
     The code in your message is an excellent example of child packages,
which has to do with inheritance.  (Your code may have a few minor syntax
errors, such as "procedure HardDrive;" instead of "procedure HardDrive is"
in the package body.)  An example of polymorphism would involve _types_,
such as the tagged type Date in the tutorial.
     I hope this helps.  By the way, I'm presently working on a minor
update of Ada Tutor, which I expect to make available on the Web and by
FTP.  I'll announce it here as soon as it's released.
- John Herro
Software Innovations Technology




       reply	other threads:[~1996-01-08  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <slrn4eumdg.4d.cabal@TerpTavern.umd.edu>
1996-01-08  0:00 ` John Herro [this message]
1996-01-08  0:00   ` Example of object oriented Ada95 requested! Robert Dewar
1996-01-08  0:00 ` Tucker Taft
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox