comp.lang.ada
 help / color / mirror / Atom feed
* OO vs Reality:  An Ada 95 Solution?
@ 1996-12-14  0:00 Marc A. Criley
  1996-12-14  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 2+ messages in thread
From: Marc A. Criley @ 1996-12-14  0:00 UTC (permalink / raw)



OO vs Reality:  An Ada 95 solution?

A dilemma often occurs when implementing an OO solution to a particular
implementation problem.  Given a well-defined, cohesive class, the
preferred Ada implementation is to implement the class within a single
package.  The class attributes are defined as private, limited, private, or
hidden in the body, as appropriate.  The operations (or services or methods
or whatever) are defined in the package spec to permit manipulation of
class objects.

The problem arises when some small bit of information about this class is
needed by another, such as the values a particular attribute may hold.  The
entire class in which those values are defined gets dragged along with that
type definition.  One might argue that smart compilers/linkers/code
strippers can remove the unnecessary code, but I feel that misses the
point.  Why should all the operations be brought in when all that's needed
is (for instance) an index range?

The needed attribute type definition could be pulled out of the class and
placed in a (gasp!) common types package, but where does that end?
Eventually most of the types get migrated to such packages, with only
attribute declarations and operations remaining in the now not-so-cohesive
class package.

Utilizing Ada 95's child packages could provide a compromise solution (or
bastardization, depending on how you look at it. :-)  The following is
submitted for discussion:

A package is created to contain the class' attributes (if appropriate),
accessors, constructors, destructors, and _very_ primitive operations,
i.e., the class is effectively useless without them.  A child package is
then created to supply the specifications for the class operations.  This
permits those other classes that need only access to attributes or their
type definitions to simply "with" the parent package, while those classes
that do more extensive manipulation can "with" the child package.
Cohesiveness is maintained, albeit in a parent-child package relationship,
which Ada 95's semantics bind far more closely than with the usual types
package/procedures package relationship.

This seems to me to be a good compromise, that is, I'm not totally ga-ga
over it, but it does seem to resolve the dilemma rather effectively.  I'm
interested in comments, criticisms, and earlier references to this
technique.

One last note: To be able to migrate to this technique when one is
currently using Ada 83, the appropriate implementation is to collect all
attributes and operations into a single package and just live with the
excess for now.  When the time to migrate to Ada 95 arrives, it becomes a
mostly mechanical process to split the class package into parent and child,
and then change references to the operations to reflect their new location
in the child package.

Marc A. Criley
Software Practitioner

OOA = (Re)packaging, OOA /= Decomposition





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-12-14  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-14  0:00 OO vs Reality: An Ada 95 Solution? Marc A. Criley
1996-12-14  0:00 ` Matthew Heaney

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