comp.lang.ada
 help / color / mirror / Atom feed
From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Object-Oriented style question
Date: Wed, 08 Feb 2012 13:23:50 +0100
Date: 2012-02-08T13:23:50+01:00	[thread overview]
Message-ID: <op.v9c0p0rpule2fv@douda-yannick> (raw)
In-Reply-To: 4f098fcb$0$6577$9b4e6d93@newsspool3.arcor-online.net

Le Sun, 08 Jan 2012 13:45:00 +0100, Georg Bauhaus  
<rm-host.bauhaus@maps.futureapps.de> a écrit:

> Given a tagged O-O type T in package Pak and a "method" of T,
> called "Info". Method Info queries the state of its parameter,
> which is of type T. States are of a type named "Value", which
> also happens to be defined in Pak.
> […]
> My question is about the best way to declare the Info operation,
> and its parameter profile in particular.
> […]
>     type Value is range 1000 .. 1003;
>
>     type T is abstract tagged private;
>
>     function Info (Item : in T) return Value;
>     function Info_1 (Item_Doubly_Indirect : access T) return Value;
>     function Info_2 (Item_Doubly_Indirect : access constant T) return  
> Value;
>     function Info_3 (Item_Doubly_Indirect : not null access constant T)  
> return Value;
> […]
> Info_2 is still close to the meaning of a query function except
> that the parameter may be null. This then means that there is *no*
> object of type T'Class and, consequently, there cannot be a state!
> Programs that call Info_2 could then needlessly raise an exception.
> (If "null" is somehow important in a set of objects from
> the T hierarchy, this does not preclude testing for "null",
> since the test can be performed at the place in the program
> where both the null pointer and the test are needed (and a default
> state value assigned).)

Yes, but with the need to repeat the test at every call place. This would  
also mean possibly different interpretation at each call place. If  
multiple interpretation are intended, that's OK, otherwise, this would be  
error‑prone (and redundant with no added value).

On the other hand, giving Null a meaning in the sense of the meaning  
associated with an instance of a type, is a bad idea (ambiguous and lacks  
evidence from the reader's point of view), and a special state or value of  
the type is better.

For the above reasons, I would exclude both Info_1 and Info_2.

Now, as you noted Info_3 fall into the same as Info, leaving a single  
question: why use an access type ? As T is a private record type, if it  
needs access type for sharing, this could be encapsulated, and Info_3 may  
be dropped in favor of Info.

 From my point of view, the classical way to do with Info, is also the best  
of the above four.

-- 
“Syntactic sugar causes cancer of the semi-colons.” [1]
“Structured Programming supports the law of the excluded muddle.” [1]
[1]: Epigrams on Programming — Alan J. — P. Yale University



  parent reply	other threads:[~2012-02-08 12:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-08 12:45 Object-Oriented style question Georg Bauhaus
2012-01-08 12:52 ` Simon Wright
2012-01-08 13:25   ` Dmitry A. Kazakov
2012-01-08 14:18 ` Robert A Duff
2012-01-08 20:32   ` Martin Dowie
2012-01-08 20:52     ` Robert A Duff
2012-01-09 22:34   ` Adam Beneschan
2012-01-09 23:21     ` Robert A Duff
2012-01-10  8:34     ` Dmitry A. Kazakov
2012-01-09  8:55 ` Maciej Sobczak
2012-01-09 23:58   ` Georg Bauhaus
2012-01-10  8:47     ` Maciej Sobczak
2012-01-10 10:27       ` Dmitry A. Kazakov
2012-01-10 12:27       ` Georg Bauhaus
2012-01-11  8:54         ` Maciej Sobczak
2012-01-10 21:26       ` Randy Brukardt
2012-02-08 12:23 ` Yannick Duchêne (Hibou57) [this message]
2012-02-08 12:39 ` Yannick Duchêne (Hibou57)
replies disabled

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