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!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: OO problem: Performing actions on messages (very long, sorry) Date: Mon, 3 Jan 2005 15:14:14 +0100 Organization: cbb software GmbH Message-ID: <8oknh024yb43$.71qlyp6g8y2x$.dlg@40tude.net> 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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: individual.net lt6PZw71VirAuiOPS7Vy4A+U9SmfwKwC92UiKJRcfhQbUGne0= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:7406 Date: 2005-01-03T15:14:14+01:00 List-Id: On 3 Jan 2005 04:37:03 -0800, per wrote: >>> 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) Neither it knows that M1 has Put. Again there is no difference. > 2. Action should cope with any Message (M1, M2, etc). So they have to have something in common. What? The name "Put"? It is too little and as good as ":=". > 3. Action should cope with any type of the field to overwrite. What is known about *any* type? Nothing. So what can action do with that? Also nothing. > 4. The value to overwrite _with_ is determined at run-time (by the user). Value or type. It is a great difference. A value determined at run-time? Here: I : Integer; begin I := ; A type determined at run-time? That is either class-wide or variant record. > 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). Appropriate arguments constitute no language entity. Specific Put means that Put is polymorphic. It means that there is *one* Put, implemented by many specific overridings of Put according to the concrete type of a polymorphic (class-wide) parameter. But it is *one* Put, with *one* parameter profile, of *one* root type. > Argh, I thought Ada would be a blessing. That old C construct 'void *' > should have been handy... Observe that void * is a type. Exactly one type. You cannot achieve what you describe with void *. It is rather C++'s ellipsis ".." what you are talking about. But neither ".." nor "void *" arguments cannot be dispatching. You have to bring *all* possible variants under one roof. There are many ways to do it. >>> 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). type Message_Value is abstract tagged; procedure Put (Action : Action_Type'Class, Value : Message_Value); -- This dispatches on Value >>> 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. Who determines what action to apply? Above you talked about actions dealing with polymorphic messages. That means that the message type (its type tag buried in a class-wide value) determines the action. Is that correct? If yes, then definitely actions are just methods of Message. What is Execute then? > 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) So message is a polymorphic value. This is the variant 1. If message may contain more than one value then it is a container of Message_Value. > 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. Try to explain it in C++ terms. Draw a class diagram. What are relationships between Message, Action, Execute? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de