comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Decoupled Mutual Recursion Challenger [Was: Mut. Recurs. in Ada9X w/o Breaking Encaps.? (LONG)]
Date: 11 Oct 1994 13:58:30 GMT
Date: 1994-10-11T13:58:30+00:00	[thread overview]
Message-ID: <37e5m6$oh0@watnews1.watson.ibm.com> (raw)
In-Reply-To: 1994Oct7.130100.26953@swlvx2.msd.ray.com

In article <1994Oct7.130100.26953@swlvx2.msd.ray.com>, jgv@swl.msd.ray.com
(John Volan) writes: 

|> So far on this thread, all the solutions to the "withing" problem
|> (decoupled mutual recursion in Ada9x) share one common feature: They
|> have all used type derivation and inheritance to support the
|> distinction between "opaque" and "transparent" object identities, with
|> the translation between them being handled by safe downcasting
|> ("narrowing") and safe upcasting ("widening"?).
...
|>
|> The trouble with solutions that exploit inheritance is that they use
|> it solely as a mechanism for decoupling, without (as Adam Beneschan
|> pointed out) correlating it to any true generalization/specialization
|> relationship present within the problem domain.  It can be argued that
|> this is an abuse of the inheritance mechanism, an example of the
|> reason why inheritance has been branded by some as the "GOTO of the
|> Nineties".  In fact, such inheritance schemes can even *get in the
|> way* of more "legitimate" uses of inheritance that do implement
|> generalization/specialization relationships.

I think this is a natural and appropriate use of inheritance.  To review,
the scheme in question is: 

    package Type_1_Parent_Package is
       type Type_1_Parent is tagged null record;
       type Type_1_Pointer is access all Type_1_Parent'Class;
    end Type_1_Parent_Package;

    package Type_2_Parent_Package is
       type Type_2_Parent is tagged null record;
       type Type_2_Pointer is access all Type_2_Parent'Class;
    end Type_2_Parent_Package;

    with Type_2_Parent_Package;
    package Type_1_Parent_Package.Refinement is
       type Type_1 is new Type_1_Parent with private;
       -- declaration of various primitive Type_1 subprograms, including
       --   some involving Type_2_Pointer
    private
       type Type_1 is new Type_1_Parent with
          record
             Associated_Type_2_Value: Type_2_Pointer;
             -- other components
          end record;
    end Type_1_Parent_Package.Refinement;

    with Type_1_Parent_Package;
    package Type_2_Parent_Package.Refinement is
       type Type_2 is new Type_2_Parent with private;
       -- declaration of various primitive Type_2 subprograms, including
       --   some involving Type_1_Pointer
    private
       type Type_2 is new Type_2_Parent with
          record
             Associated_Type_1_Value: Type_1_Pointer;
             -- other components
          end record;
    end Type_2_Parent_Package.Refinement;

The type Type_1_Parent models some real-world entity, perhaps an office
or an employee.  When a type models a real-world entity, it does not
model every property of that entity, only those that are relevant to the
intended use of the type.  For example, a type modeling an employee might
not include a Favorite_Scotch component if that information is not
relevant to the application.  The only feature of Type_1_Parent is its
ability to be pointed to by a Type_1_Pointer value.

The type Type_1 is a specialization of Type_1_Parent.  The real-world
entity it models happens to be the same as that modeled by Type_1_Parent,
but it provides a more specialized VIEW of that entity, one that offers
not only the ability to be pointed to by a Type_1_Pointer value, but a
number of primitive subprograms as well.  An instance of Type_1 "is an"
instance of Type_1_Parent, because it can be used in the same way as any
other instance of Type_1 (and in additional ways as well).

There is nothing wrong with a class and a subclass modeling the same
real-world entity, but with the subclass providing a more specialized
view of that entity, with a more complete programming interface.

--
Norman H. Cohen    ncohen@watson.ibm.com



       reply	other threads:[~1994-10-11 13:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1994Oct7.130100.26953@swlvx2.msd.ray.com>
1994-10-11 13:58 ` Norman H. Cohen [this message]
1994-10-12 13:17   ` Decoupled Mutual Recursion Challenger John Volan
     [not found] ` <1994Oct7.165517@di.epfl.ch>
     [not found]   ` <1994Oct7.222716.8690@swlvx2.msd.ray.com>
     [not found]     ` <1994Oct11.122356@di.epfl.ch>
1994-10-11 23:34       ` John Volan
replies disabled

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