From: ka@sorry.no.email (Kenneth Almquist)
Subject: Re: Q: Endless loop by dispatching
Date: 15 Jul 2003 03:11:51 -0400
Date: 2003-07-15T03:11:51-04:00 [thread overview]
Message-ID: <bf09fn$hk2$1@shell.monmouth.com> (raw)
In-Reply-To: 3F0FC8C7.4090105@snafu.de
Michael Erdmann <michael.erdmann@snafu.de> wrote:
> Thanks. In fact i have now selected this aproach. Each package
> derives from the base type (A.Object) is forced to implement
> a procedure Serialize by definint it in A as abstract.
>
> The bad thing about it, is that i wanted to add some code
> which is common to all implementation of A.Object in the
> Central Serialize procedure (e.g. writing the attrbiute
> name if ront of every field of B.Object) Now i have to duplicate
> this code in all implementations of A.Object.
The way to avoid duplicate code is to place the code in a generic
procedure which is instantiated for each type. Something along
the line of:
package A is
type Object is tagged private;
-- Write out all of the attributes of an object.
procedure Serialize(This : Object);
-- Write the value of a single attribute.
procedure Write(This : Object; Attribute : Attribute_Id);
-- Serialize_Extension for type T writes the attributes
-- which appear in T type but not in the parent of type T.
generic
type T is new Object with private;
Attributes : in Attribute_Array;
with procedure Write(This : Object; Attribute : Integer) is <>;
procedure Serialize_Extension(This : Object);
end A;
package B is
type Object is new A.Object with private;
-- Write out all of the attributes of an object.
procedure Serialize(This : Object);
-- Write the value of a single attribute.
procedure Write(This : Object; Attribute : Attribute_Id);
end B;
package body B is
My_Attributes : constant Attribute_Array := (...);
procedure Serialize(This : Object) is
procedure SE is new Serialize_Extension(Object, My_Attributes);
begin
Serialize(A.Object(This));
SE(This);
end Serialize;
procedure Write(This : Object; Attribute : Attribute_Id) is ...;
end B;
Kenneth Almquist
prev parent reply other threads:[~2003-07-15 7:11 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-11 8:22 Q: Endless loop by dispatching Michael Erdmann
2003-07-11 9:46 ` Jean-Pierre Rosen
2003-07-11 15:19 ` Michael Erdmann
2003-07-11 10:01 ` Q: " Dmitry A. Kazakov
2003-07-11 15:07 ` Michael Erdmann
2003-07-12 1:41 ` Jeffrey Carter
2003-07-14 8:48 ` Dmitry A. Kazakov
2003-07-14 18:38 ` Randy Brukardt
2003-07-15 8:47 ` Dmitry A. Kazakov
2003-07-15 17:23 ` Randy Brukardt
2003-07-16 8:08 ` Dmitry A. Kazakov
2003-07-16 17:44 ` Robert I. Eachus
2003-07-17 1:57 ` Robert A Duff
2003-07-18 9:10 ` Dale Stanbrough
2003-07-18 20:26 ` Robert I. Eachus
2003-07-18 21:35 ` tmoran
2003-07-19 0:25 ` Robert I. Eachus
2003-07-19 2:30 ` tmoran
2003-07-19 5:48 ` Robert I. Eachus
2003-07-21 8:38 ` Dmitry A. Kazakov
2003-07-21 10:08 ` Robert I. Eachus
2003-07-21 13:21 ` Dmitry A. Kazakov
2003-07-21 18:51 ` Robert I. Eachus
2003-07-22 7:41 ` Dmitry A. Kazakov
2003-07-22 10:36 ` Lutz Donnerhacke
2003-07-22 12:11 ` Dmitry A. Kazakov
2003-07-22 12:18 ` Lutz Donnerhacke
2003-07-22 14:46 ` Dmitry A. Kazakov
2003-07-22 15:11 ` Lutz Donnerhacke
2003-07-23 8:12 ` Dmitry A. Kazakov
2003-07-19 14:44 ` Chad R. Meiners
2003-07-20 12:36 ` Robert I. Eachus
2003-07-11 16:27 ` T. Kurt Bond
2003-07-12 8:37 ` Michael Erdmann
2003-07-15 7:11 ` Kenneth Almquist [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox