comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de>
Subject: Re: [newbie] simple(?) data structures
Date: Sun, 13 Jun 2004 10:12:17 +0000 (UTC)
Date: 2004-06-13T10:12:17+00:00	[thread overview]
Message-ID: <cah9a1$1qd$1@a1-hrz.uni-duisburg.de> (raw)
In-Reply-To: 2j21dlFrvu2sU1@uni-berlin.de

Roland Illig <roland.illig@gmx.de> wrote:
: tmoran@acm.org wrote:
:> Why so complicated?  Why not just:
:>   type Go_Board is array(integer range <>,integer range <>) of Stone;
:>   This_Board : Go_Board(1 .. 19, 1 .. 19);
:>   That_Board : Go_Board(1 .. 13, 1 .. 13);
:> then directly access the array instead of getStone, and use
:> This_Board'length(1) instead of getHeight and This_Board'length(2) for getWidth
: 
: That's too simple. :)
: 
: Seriously, I want to build abstractions using Ada,

As has been suggested, you don't need a whole lot of language
support to build the abstraction. For example, if only the size
of the board is a variable property of a Go board (once, when a
variable of type Go_Board is declared), type extensions are not
needed, neither are generics.
When there are no other properties that need to be seen from the
outside, then with a suitably defined Board_Size index type,

   type Go_Board (rows, columns: Board_Size) is private;

   -- ... subprogram declarations of the type Go_Board

Note that rows and columns are *constants* in a discriminated subtype
once you have declared a new board,

   my_board: Go_Board(rows => 13, columns => 19);

So this is one possible equivalent of a (the outside view of)
the constructor.  No variable parts of Go_Board are exposed, quite
abstract :-) You can pass my_board around, using the Go_Board
subprograms.

You are now free to place any implementation detail in the private
part, as has been demonstrated, the Go_Board subprograms will
be able to see them.

So if, for implementation, you use a 2-dimensional
array, as in you C++ example, and as in Tom Moran's example,
you can make it a part of the full type's declaration 
in the private part, *and* you can use both rows, columns
and array attributes in the Go_Board subprograms.

Maybe, if there is are default values for rows and columns in
a Go board, you can use the like this:

package Go.Boards is

   type Go_Board
     (rows: Board_Size := 13; columns: Board_Size := 19)
   is private;

   -- ... subprogram declarations

private

  -- ... declarations of Cell, Cell_Array, etc

  type Go_Board
     (rows: Board_Size := 13; columns: Board_Size := 19)
   is record
     cells: Cell_Array(1..rows, 1..columns);
   end record;

end Go.Boards;



  reply	other threads:[~2004-06-13 10:12 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-12 22:23 [newbie] simple(?) data structures Roland Illig
2004-06-12 22:52 ` Frank
2004-06-13  0:10 ` Ludovic Brenta
2004-06-13  3:13   ` Roland Illig
2004-06-13  7:59     ` Marius Amado Alves
2004-06-13 11:56       ` Ludovic Brenta
2004-06-13 14:47     ` Stephen Leake
2004-06-13 18:24       ` Jeffrey Carter
2004-06-13  0:31 ` Jeffrey Carter
2004-06-13  1:26 ` tmoran
2004-06-13  2:47 ` tmoran
2004-06-13  3:53   ` Roland Illig
2004-06-13 10:12     ` Georg Bauhaus [this message]
2004-06-13 23:32       ` Robert I. Eachus
2004-06-14 12:29         ` Georg Bauhaus
2004-06-13  4:46 ` Steve
2004-06-13  4:59   ` tmoran
2004-06-13 17:58     ` Jeffrey Carter
2004-06-16 11:08 ` Roland Illig
2004-06-16 21:05   ` Georg Bauhaus
2004-06-16 23:23     ` Roland Illig
2004-06-17  0:44       ` Jeffrey Carter
2004-06-17 12:37         ` Hyman Rosen
2004-06-17 13:11           ` Björn Persson
2004-06-18  9:55             ` Ole-Hjalmar Kristensen
2004-06-18 11:03               ` Björn Persson
2004-06-18 12:04               ` Hyman Rosen
2004-06-22  8:11                 ` Ole-Hjalmar Kristensen
2004-06-18  0:20           ` David Starner
2004-06-18  5:06             ` Hyman Rosen
2004-06-18  5:47               ` Martin Krischik
2004-06-18  7:30                 ` Brian May
2004-06-18 14:21                 ` Larry Kilgallen
2004-06-19 19:51                 ` Robert I. Eachus
2004-06-18 15:04               ` Georg Bauhaus
2004-06-19  2:02               ` James Rogers
2004-06-18  9:51           ` Ole-Hjalmar Kristensen
2004-06-27 13:12   ` Jacob Sparre Andersen
2004-06-24  0:09 ` Matthew Heaney
2004-06-24 14:50   ` Nick Roberts
replies disabled

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