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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a8d137db7a5f6c81 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail From: "per" Newsgroups: comp.lang.ada Subject: Re: OO problem: Performing actions on messages (very long, sorry) Date: 5 Jan 2005 07:59:05 -0800 Organization: http://groups.google.com Message-ID: <1104940745.420814.235130@f14g2000cwb.googlegroups.com> References: <1103723394.299024.314670@c13g2000cwb.googlegroups.com> <13465377.hrn0RlrJV7@linux1.krischik.com> <1103737351.196460.85450@f14g2000cwb.googlegroups.com> <1qdvdjid4u58v.1xz6j5ec6nfcy$.dlg@40tude.net> <1104755823.837077.74630@z14g2000cwz.googlegroups.com> <8oknh024yb43$.71qlyp6g8y2x$.dlg@40tude.net> <1104840326.160879.132400@c13g2000cwb.googlegroups.com> <1ogeykubpns90.2jnblmdu1wg2.dlg@40tude.net> <1104852099.054703.265080@f14g2000cwb.googlegroups.com> <1104926478.797780.7830@c13g2000cwb.googlegroups.com> <1odpvi9429wrb.r854wtzbr1qm$.dlg@40tude.net> NNTP-Posting-Host: 138.14.239.132 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1104940752 7013 127.0.0.1 (5 Jan 2005 15:59:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 5 Jan 2005 15:59:12 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=138.14.239.132; posting-account=e84-wQ0AAADeDLnjH5yWqnRMVsJLfQJg Xref: g2news1.google.com comp.lang.ada:7479 Date: 2005-01-05T07:59:05-08:00 List-Id: >> But... What if the descendant to Message has many fields of the same >> type (as definitely is the case for me): > >> type Message.M1 is new Message with >> record >> A : Integer; >> B : Integer; >> end; > >> What field would be assigned by > >> procedure Put (M : in out Message.M1; Value : Integer); > >It is a suspicious design. What is the difference between fields A and B? >Only names? If so then there should be an integer array instead. So you go >as follows: > >type Index is new Positive; >type Integer_List is array (Index range <>) of Integer; >procedure Put (M : in out Message; Value : Integer; Position : Index); > >type Message.M1 (List_Size : Natural) is new Message with record > List : Integer_List (1..Size); >end record; > >If there is some semantic difference between A and B, then from design >point of view it has to be mapped into types. So you will have: > >type Port_Number is new Integer range 1..10_000; >type Annual_Income is new Integer range 0..100_000_000; > >procedure Put (M : in out Message; Value : Port_Number); >procedure Put (M : in out Message; Value : Annual_Income); > >Ada encorages and assists design in terms the application domain, rather >than focused on implementation details. Ah, I get it. In my example A and B were supposed to have different sematics. The messages in this system are actually unknown right now. My system shall simulate many different devices and their communication. The message specifications are defined by each device vendor, not by us (the team). Hence the message contents is quite unknown and I'd like to cope with "anything". We can however implement the messages in any way we like as long as we can convert it to some format that can be sent on different hardware communication linkst in some defined way. ... >OK, I see. But then the question to answer what purpose serves message >apart from being just a container for unrelated data? The difficulties of >the design come from that missing pupose. If there is nothing in common >then nothing can be programmed for that nothing. (:-)) Well, each message *is* a simple container, more or less. The contents are related in the sense they are to be sent to/from a certain device that expects a defined set of information. The program we discuss doesn't really care at all of the contents of each message, but shall provide means to the user to override any message content (among other things). >Hmm, what about this mix-in: > >package Interfaces is > type Message is abstract tagged ... > type Action is abstract tagged limited ...; > procedure Execute (This : in out Action) is abstract; >end Interfaces; > >package M1_Thinds is > type M1 is new Message with record -- Message M1 > A : Integer; > B : Float; > end record; > > type M1_Action (Data : access M1) is -- Abstract actions on M1 > abstract new Action with null record; > > type Override_A is new M1_Action with record > A : Integer; > end record; > procedure Execute (This : in out Override_A); > > type Override_B is new M1_Action with record > B : Float; > end record; > procedure Execute (This : in out Override_B); > ... > >package body M1_Things > procedure Execute (This : in out Override_A) is > begin > This.Data.A := This.A; > end Execute; > > procedure Execute (This : in out Override_B) is > begin > This.Data.B := This.B; > end Execute; > >Here all actions on some type of messages have a "pointer" to the >corresponding message object. The scope of an action should be nested in >the scope of the message. > >Here in fact action is a pointer to message extended with some additional >data. When scopes get different, then action could be a handle to message. >Messages will be collected using reference counting. I kind of see what this aims at (although "mix-in" is new to me). As far as I see we're back to defining one action type for each message and each field in the message, although this time without the generics, right? Can an action, eg Override_A, exist without an M1 instance to "point" at? Action has a different life-cycle than Message.