comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: "Classes" as packages in Ada
Date: 1999/03/28
Date: 1999-03-28T00:00:00+00:00	[thread overview]
Message-ID: <m3677ltjqx.fsf@mheaney.ni.net> (raw)
In-Reply-To: EACHUS.98Nov25182652@spectre.mitre.org

eachus@spectre.mitre.org (Robert I. Eachus) writes:

>    But if I wanted to simply implement the Ada equivalent to John's
> classes, I'd probably use an Ada protected object.  (Note to Ada 95
> programmers, this is a perfect case for using requeue to insure that
> each observer is notified once for each event.)
> 
>     protected type Observed_Object is
>       procedure Set(Observed: in Object);
>       function Value return Object;
>       entry Modified(Observed: out Object);
>     private
>       entry Waiting(Observed: out Object);
>       Current: Object;
>       Reporting: Boolean := False;
>     end Observed_Object;
>        
>     protected body Observed_Object is
>       procedure Set (Observed: in Object) is
>       begin
>         Current := Observed;
>         Reporting := True;
>       end Set;
> 
>       function Value return Object is begin return Current; end Value;
> 
>       entry Modiified(Observed: out Object) when not Reporting is  
>       begin requeue Waiting; end;
> 
>       entry Waiting(Observed: out Object) when Reporting is
>       begin
>         Observed := Current;
>         if Waiting'Count = 0 then Reporting := False; end if;
>       end; 
> 
>     end Observed_Object;
> 
>     Now I probably could spend pages describing why I made certain
> choices in this version, and how to modify it to deal with other
> cases, but I'll refrain.  (Knowing the list though, I'm sure there
> will be a dozen variations posted by Monday ;-)


Oh, they were posted by Monday, just not the Monday you had in mind. ;^)

In the March 99 ACM patterns archive, you'll find these examples of the
Observer pattern:

  observer (see also revised version)
  observer is subject
  observers of multiple subjects
  mediator
  mediator (alternate version)


I have converted every example in the GoF Design Patterns book to Ada95,
and posted them to the ACM patterns list.

<mailto:patterns@acm.org>
<http://www.acm.org/archives/patterns.html>

You can subscribe to the patterns list by sending the message (body)

subscribe patterns <your full name>


to the ACM mailing list server.

<mailto:listserv@acm.org>


Matt










  parent reply	other threads:[~1999-03-28  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-24  0:00 "Classes" as packages in Ada Samuel Mize
1998-11-24  0:00 ` John Goodsen
1998-11-25  0:00   ` Ed Falis
1998-11-25  0:00     ` John Goodsen
1998-11-25  0:00       ` Robert I. Eachus
1998-11-28  0:00         ` Brian Rogoff
1998-11-30  0:00         ` Robert I. Eachus
1999-03-28  0:00         ` Matthew Heaney [this message]
1998-11-27  0:00       ` Larry Kilgallen
1999-03-28  0:00       ` Matthew Heaney
replies disabled

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