comp.lang.ada
 help / color / mirror / Atom feed
* Interface to aggregated type
@ 2012-08-06 18:42 ms
  2012-08-06 19:43 ` Dmitry A. Kazakov
  2012-08-06 19:56 ` Marius Amado-Alves
  0 siblings, 2 replies; 4+ messages in thread
From: ms @ 2012-08-06 18:42 UTC (permalink / raw)


My question is half-ada/half-architectural, I'll explain it on simple HTTP server example.

Imagine HTTP library providing two packages - `Headers` which provides container for HTTP headers (`Header_Container` type) and `Requests` which is a abstraction over HTTP request message (`Request` type).

Clearly `Request` aggregates `Header_Container`, as HTTP requests generally contain some set of headers.

My dilemma is - `Headers` package already provides some sort of `Header_Container` manipulation interface - procedures for inserting and deleting headers and functions to return them, but I want allow these operations also on container aggregated inside `Request` type (which is probably a private record).

Now I have several options such as duplicating header manipulation interfaces entirely (eg. function Header_Value (R : Request, Name : String) in `Requests` package) or making aggregated `Header_Container` field public (can I make only some of the record's fields public and leave others private?). Both have pros and cons, and possibly even more solutions exist.

What would you do?



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

* Re: Interface to aggregated type
  2012-08-06 18:42 Interface to aggregated type ms
@ 2012-08-06 19:43 ` Dmitry A. Kazakov
  2012-08-06 20:28   ` ms
  2012-08-06 19:56 ` Marius Amado-Alves
  1 sibling, 1 reply; 4+ messages in thread
From: Dmitry A. Kazakov @ 2012-08-06 19:43 UTC (permalink / raw)


On Mon, 6 Aug 2012 11:42:03 -0700 (PDT), ms wrote:

> Clearly `Request` aggregates `Header_Container`, as HTTP requests
> generally contain some set of headers.
> 
> My dilemma is - `Headers` package already provides some sort of
> `Header_Container` manipulation interface - procedures for inserting and
> deleting headers and functions to return them, but I want allow these
> operations also on container aggregated inside `Request` type (which is
> probably a private record).

If Request implements the interface of Header_Container and also aggregates
it, why don't you derive one from another?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Interface to aggregated type
  2012-08-06 18:42 Interface to aggregated type ms
  2012-08-06 19:43 ` Dmitry A. Kazakov
@ 2012-08-06 19:56 ` Marius Amado-Alves
  1 sibling, 0 replies; 4+ messages in thread
From: Marius Amado-Alves @ 2012-08-06 19:56 UTC (permalink / raw)


Don't duplicate. Not here. Not needed. Make distinct packages HTTP.Headers, HTTP.Request_Messages, etc. Top package HTTP may have common things e.g. a root type for messages, or may be empty; HTTP.Request_Messages uses (withens) HTTP.Headers; you can make a type T1 with public and private fields easily using type extension(maybe there are other ways):

   type T0 is tagged
      record
         <public fields>
      end record;

   type T1 is new T0 with private;
private
   type T1 is new T0 with
      record
         <private fields>
      end record;



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

* Re: Interface to aggregated type
  2012-08-06 19:43 ` Dmitry A. Kazakov
@ 2012-08-06 20:28   ` ms
  0 siblings, 0 replies; 4+ messages in thread
From: ms @ 2012-08-06 20:28 UTC (permalink / raw)
  Cc: mailbox

On Monday, August 6, 2012 9:43:22 PM UTC+2, Dmitry A. Kazakov wrote:
> On Mon, 6 Aug 2012 11:42:03 -0700 (PDT), ms wrote:
> 
> 
> 
> > Clearly `Request` aggregates `Header_Container`, as HTTP requests
> 
> > generally contain some set of headers.
> 
> > 
> 
> > My dilemma is - `Headers` package already provides some sort of
> 
> > `Header_Container` manipulation interface - procedures for inserting and
> 
> > deleting headers and functions to return them, but I want allow these
> 
> > operations also on container aggregated inside `Request` type (which is
> 
> > probably a private record).
> 
> 
> 
> If Request implements the interface of Header_Container and also aggregates
> 
> it, why don't you derive one from another?
> 
> 
> 
> -- 
> 
> Regards,
> 
> Dmitry A. Kazakov
> 
> http://www.dmitry-kazakov.de

This is one of these "how did I missed that" ideas. Thanks!



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

end of thread, other threads:[~2012-08-13  9:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-06 18:42 Interface to aggregated type ms
2012-08-06 19:43 ` Dmitry A. Kazakov
2012-08-06 20:28   ` ms
2012-08-06 19:56 ` Marius Amado-Alves

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