comp.lang.ada
 help / color / mirror / Atom feed
From: doylep@ecf.toronto.edu (Patrick Doyle)
Subject: Re: Visibility and access to "public" attributes
Date: 1997/08/29
Date: 1997-08-29T00:00:00+00:00	[thread overview]
Message-ID: <EFotFL.I5t@ecf.toronto.edu> (raw)
In-Reply-To: 872873007.3110@dejanews.com


In article <872873007.3110@dejanews.com>,  <card@syr.lmco.com> wrote:
>
>package Test1 is
>   type My_Type is tagged private;           -- attributes invisible
>   function A(Obj : My_Type) return Boolean; -- access function
>private
>   type My_Type is tagged
>      record
>         A : Boolean;                        -- attribute
>      end record;
>end Test1;
>
>
>package body Test1 is
>   function A(Obj : My_Type) return Boolean
>   is
>   begin
>      return Obj.A;
>   end A;
>end Test1;
>
>Thus, there is no restriction in Ada that prevents an access function
>from having the same name as a class' (tagged type's) attribute.

  Ok, but remember that this same piece of code would look like
this in Eiffel:

class TEST1

feature

  A : BOOLEAN

end

  Of course, every language has things it's good at and things
it's not so good at, but this to me seems a fairly common pattern
in OOP.

>That said, I think it is fair to say that I believe the idea behind
>Ada's "all or nothing" approach is that you may want to ensure that
>a client never depends on some of a type's attributes. For instance,
>you might have an Aircraft class with a Take_Off method. Should a
>client be able to view (and thus potentially depend upon) attributes
>in the Aircraft type that might change but would not impact the
>interface to Take_Off?

  If the attributes change, then what used to be an attribute
can be changed into a function with absolutely no effect on
client code.  (And, if it turns out to be impossible to do
this, then you have a problem on your hands even in Ada.)
The Eiffel approach is *no different* from using accessors.

>I know that Eiffel can totally hide the attributes of an object (i.e.
>accessed via methods only) as well. When writing Eiffel programs, how
>do you decide when to make a type's attributes "read-only visible"
>and when to hide them?

  The same way you decide in Ada whether or not to provide an
accessor function.

  What I'd like to know is, how do you decide in Ada whether
to make an attribute public, and thus irrevocably commit to
allowing clients to assign to it?

 -PD

-- 
--
Patrick Doyle
doylep@ecf.utoronto.ca




  reply	other threads:[~1997-08-29  0:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-08-29  0:00 Visibility and access to "public" attributes card
1997-08-29  0:00 ` Patrick Doyle [this message]
     [not found]   ` <JSA.97Aug29190453@alexandria.organon.com>
1997-08-30  0:00     ` Patrick Doyle
1997-08-30  0:00       ` Jon S Anthony
1997-09-01  0:00         ` Patrick Doyle
1997-08-30  0:00 ` Darren New
1997-09-02  0:00 ` Don Harrison
1997-09-02  0:00   ` Don Harrison
1997-09-02  0:00     ` Jon S Anthony
1997-09-02  0:00     ` Gavin Collings
1997-09-02  0:00       ` Patrick Doyle
1997-09-02  0:00       ` Nick Leaton
1997-09-02  0:00         ` Gavin Collings
1997-09-03  0:00       ` Don Harrison
1997-09-05  0:00       ` Nick Leaton
     [not found]         ` <01bcba0e$418f7380$2001df0a@gavinspc>
1997-09-05  0:00           ` Nick Leaton
1997-09-05  0:00         ` Patrick Doyle
1997-09-02  0:00   ` Peter Horan
  -- strict thread matches above, loose matches on Subject: below --
1997-08-29  0:00 card
1997-08-29  0:00 ` Ted Velkoff
1997-08-30  0:00 ` Patrick Doyle
1997-08-30  0:00 ` Darren New
1997-09-02  0:00 card
replies disabled

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