comp.lang.ada
 help / color / mirror / Atom feed
* Multiple dispatch
@ 2011-06-11 10:13 Yannick Duchêne (Hibou57)
  2011-06-11 11:52 ` Dmitry A. Kazakov
  2011-06-12  5:13 ` Randy Brukardt
  0 siblings, 2 replies; 13+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-06-11 10:13 UTC (permalink / raw)


Hi peoples, Hi Ada world,

In your opinion, what is the best known design pattern for multiple  
dispatch in Ada ? (as far as I know, there is no way to get multiple  
dispatching in Ada the direct way).

As with any design matters, an answer to this question will probably  
depends on the concrete case, so here is an overview of the concrete  
matter: it deals with serialization.

An example: you have multiple object of different types rooted at a some  
root type; you also have multiple containers of different types too, also  
rooted at another root type. Now, say objects are all to have a  
serialization methods, a different one for each type. This could be  
dispatching, OK, except that you have the requirement these objects are  
also to be serialized a way or another, depending on the container which  
will hold the serialized datas. Add to this that you can't change this,  
because this is part of some standard or any other kind of things already  
fixed.

Say Object_1_Type, to be serialized to Container_1_Type, will use  
Method_1_1
…  Object_1_Type, to be serialized to Container_2_Type, will use Method_1_2
… Object_2_Type, to be serialized to Container_1_Type, will use Method_2_1
… Object_2_Type, to be serialized to Container_2_Type, will use Method_2_2
… and so on

A quick solution could be :

1) Define two methods for object : one would be Serialize_To_Container_1  
and Serialize_To_Container_2.
2) Then, a master Serialize method could get two parameters, one object  
and one container,
3) This method would discriminate on container's type, so would invoke  
either Serialize_To_Container_1 or Serialize_To_Container_1 depending on  
the container's type, and this call would be dispatching on object's type.

OK, but why not the opposite ? And then, where the master dispatcher  
should reside ? In the module defining objects ? In the module defining  
containers ? In a third module ? Who should own the knowledge about  
serialization ? I feel it's natural to say, Objects, of course; but this  
also requires dispatching on container's types… Still seems natural the  
serialization should be driven by objects, at least because objects to be  
serialized may hold private stuff, or else are the only ones to know which  
of their properties are to be stored and which are to be derived from the  
ones stored.

Alternatively, may be a seed of a solution : the containers would define  
some serialization primitives for some basic property types objects are  
made of, and objects could request the container to provide these method,  
via dispatching calls.

This would end into…

Steps for the serialization of an object to a container :

1) Determine the object serialization method to use depending on its type.
2) The object is composed of properties of types Property_1_Type,  
Property_2_Type, and so on.
3) The containers provides methods Serialize_Property_Type_1,  
Serialize_Property_Type_2, and so on.
4) The object's serialization method invokes these container's methods,  
via dispatching calls.

Seems OK ? Any one see a better design pattern ? Do someone see something  
wrong with this repartitions of knowledge and responsibilities between  
modules ?

-- 
“Syntactic sugar causes cancer of the semi-colons.”  [Epigrams on  
Programming — Alan J. — P. Yale University]
“Structured Programming supports the law of the excluded muddle.” [Idem]
“c++; /* this makes c bigger but returns the old value */” [Anonymous]



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-06-15 16:21 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-11 10:13 Multiple dispatch Yannick Duchêne (Hibou57)
2011-06-11 11:52 ` Dmitry A. Kazakov
2011-06-11 13:19   ` Yannick Duchêne (Hibou57)
2011-06-11 13:57     ` Dmitry A. Kazakov
2011-06-11 18:42       ` Emmanuel Briot
2011-06-11 19:12         ` Dmitry A. Kazakov
2011-06-15 10:30       ` Natasha Kerensikova
2011-06-15 11:10         ` Yannick Duchêne (Hibou57)
2011-06-15 11:19           ` Yannick Duchêne (Hibou57)
2011-06-15 14:59         ` Georg Bauhaus
2011-06-15 15:18           ` Yannick Duchêne (Hibou57)
2011-06-15 16:21             ` Georg Bauhaus
2011-06-12  5:13 ` Randy Brukardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox