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!z14g2000cwz.googlegroups.com!not-for-mail From: "per" Newsgroups: comp.lang.ada Subject: Re: OO problem: Performing actions on messages (very long, sorry) Date: 3 Jan 2005 04:37:03 -0800 Organization: http://groups.google.com Message-ID: <1104755823.837077.74630@z14g2000cwz.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> NNTP-Posting-Host: 138.14.239.132 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1104755827 25793 127.0.0.1 (3 Jan 2005 12:37:07 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 3 Jan 2005 12:37:07 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=138.14.239.132; posting-account=e84-wQ0AAADeDLnjH5yWqnRMVsJLfQJg Xref: g2news1.google.com comp.lang.ada:7404 Date: 2005-01-03T04:37:03-08:00 List-Id: Dmitry: >> Somewhere some mechanism assigns the initial values: >> M1 : Message.M1.Instance; >> Put_A(M1, 1.0); >> Put_B(M1, 1); >> ... >> Later on, an override action shall be able to override these values by >> basically doing: >> Put_A(M1, Some_Other_Value_Stored_In_The_Action); >> again! >And why: M1.A := 10; is bad? Hm. 1. Action does not know of the internals of M1 (such as that M1.A exists) 2. Action should cope with any Message (M1, M2, etc). 3. Action should cope with any type of the field to overwrite. 4. The value to overwrite _with_ is determined at run-time (by the user). But I really don't care if I write ":=" or "Put_"; that's not the issue. I just want to be able to call a specific Put_... (or do ":=") on _any_ message with the appropriate arguments (message and field value) determined at run-time (by the user). Argh, I thought Ada would be a blessing. That old C construct 'void *' should have been handy... ... >> I would love to make Put dispatching but how would a procedure look >> like that can assign a value to any field in a record? >Variant 1. Derive all values from one base > type Message_Value is abstract tagged ... or Controlled How would that make Put dispatching? Note that the Message is a fixed record, whose fields (one or more) I want to assign one or more values to (not known at compile time etc etc). >Variant 2. Use streams. Your record will be a stream (derived from >Ada.Streams.Root_Stream_Type). For each type there are attributes 'Input >and 'Output. See ARM 13.13. That's new stuff to me, have to check it out. ... >>>> There will also be a nice general mechanism that basically gets any >>>> type of message, applies any actions enqueued for it and then puts the >>>> message away. It feels like this should be possible with Ada mechanisms >>>> such as inheritage, polymorphy and generics but, I kind of doubt it >>>> now... >>>It is definitely possible: >>>package Messages is >>> type Message is >>> abstract new Ada.Finalization.Limited_Controlled with private; >>> procedure Execute (This : in out Message) is abstract; >>> type Messages_Queue is >>> [abstract] new Ada.Finalization.Limited_Controlled with private; >>> -- Abstract if there should be different implementations of queues >>> procedure Enqueue >>> ( Queue : in out Messages_Queue; >>> Item : in out Message'Class >>> ) [is abstract]; >>>private >>> ... >>>end Messages; >>>package Messages.My_Messages is >>> type My_Message is new Message with private; >>> procedure Finalize (This : in out Message); -- How to destruct >>> procedure Initialize (This : in out Message); -- How to construct >>> procedure Execute (This : in out Message); -- What to be done >>> procedure Put_A (This : in out Message; A : Something); >>> ... >> Ugh, I don't get it. >> How could the message know what to do in Execute? There may be 0 or 5 >> or 500 actions to be taken on each message. >Ok, then replace "Message" with "Action" and make Message an Action >container. This doesn't make sense to me (probably due to that I haven't understood your idea). My gut tells my that Messages should not "contain" Actions or vice versa. They are separate structures that should interract but not "contaminate" each other. Messages are separate from Actions, have separate lives and flow in the system. Actions (may) appear in one part of the system and should be "performed on" or "applied to" Messages, but not "owned by" or "contained within" the Messages. Message instances are created, routed and destroyed (sort of) dynamically. Actions are sitting in their queues waiting for the right moment (user-defined time) to Execute. At that time a certain Message instance exist on which type the Action is programmed to Execute upon. It Executes (in this case overwrites a field in the message record with a user-defined value), then the Action is destroyed. The Message is passed on to other adventures (such as being acted upon by other Actions) The life time of Messages and Actions are hence fundamentally different. I'm afraid we don't understand eachother. Probably due to that I, being an Ada newbie, try to grasp too much at one time and also fail in explaining the problem. >The difference in the expected type. Print expects a message, >OverrideMethodRefType expects MessageType. Those are different types. The >compiler does not know about your intention to substitute message for >MessageType. Because, next day, you might change your mind and substitute >Boolean instead. OK, I can see that now.