From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1108a1,fd96375b28b3103b X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,fd96375b28b3103b X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: "Classes" as packages in Ada Date: 1999/03/28 Message-ID: #1/1 X-Deja-AN: 460108744 References: <73f0p1$4iu8$1@prime.imagin.net> <1103_911962898@DZOG-CHEN> <3UU62.124$8X3.638914@news.rdc1.az.home.com> NNTP-Posting-Date: Sun, 28 Mar 1999 12:53:50 PDT Newsgroups: comp.lang.ada,comp.object Date: 1999-03-28T00:00:00+00:00 List-Id: 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. You can subscribe to the patterns list by sending the message (body) subscribe patterns to the ACM mailing list server. Matt