comp.lang.ada
 help / color / mirror / Atom feed
* [Q] Relationships between tagged types
@ 1995-03-01  1:31 John Woodruff
  1995-03-03 14:44 ` Tucker Taft
  0 siblings, 1 reply; 4+ messages in thread
From: John Woodruff @ 1995-03-01  1:31 UTC (permalink / raw)


I'm trying to teach myself the OO features of Ada95, and sometimes I
get a little stuck.  Here is a case where I'd benefit from a little
advice.  I suspect that there is an idiomatic structure for modeling
related extensible types, but I'm stumbling.  

package Reading is 

  type Reading_Type is tagged null record ;
--
--  I hope to model some distinct devices, each kind with its own reading
--
  type continuous_reading is new Reading_Type with record
    value  : float ;
  end record ;

  type discrete_reading is new Reading_Type with record
    value  : integer ;
  end record ;

--  I am going to get a reading from one of these devices, 
--  using some dispatching operation not shown here, then
--  decide if the reading is significantly out of tolerance:

  type Tolerance is record 
     Upper, Lower : Reading_Type ;  -- this is not quite what I want!
  end record ;                      -- but 'class is not correct here

--  I wish I could express the fact that discrete readings are
--  characterized by discrete tolerances, etc ...


-- Now the point of the exercise is to require that continuous
-- readings be tested for significance against continuous tolerances, etc.
-- But I haven't seen how to do this without making the
-- functions try to dispatch on two different parameters

  function Significant (Reading : Continuous_Reading ;
			Bound   : Tolerance) return Boolean ;

  function Significant (Reading : Discrete_Reading ;
			Bound   : Tolerance) return Boolean ;

end Reading ;

The issues I wish I could model in the spec I sketched here are
  reading_type can be extended for numerous kinds of devices
  each reading_type has a corresponding tolerance type
  I want to assure that reading and tolerance values stay paired, so
operations like Significant (and other opn's tbd) will be type-safe
  There doesn't seem to be a reason for reference semantics, since I
dont see any cause for sharing access to values (thus I have not used
access types).

I'd be glad to have advice;  thanks.

-- 
John Woodruff
Lawrence Livermore National Lab
510 422 4661



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

end of thread, other threads:[~1995-03-09  3:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-03-01  1:31 [Q] Relationships between tagged types John Woodruff
1995-03-03 14:44 ` Tucker Taft
1995-03-08 12:52   ` Real-time implications of Ada 95 OO features Will Stewart
1995-03-09  3:45     ` Offer Pazy

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