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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aa7f494bf30adbc7 X-Google-Attributes: gid103376,public Path: g2news1.google.com!news1.google.com!news.glorb.com!news.cs.univ-paris8.fr!informatik.uni-bremen.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: [newbie] simple(?) data structures Date: Sun, 13 Jun 2004 10:12:17 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <2j1e30Fsrg8vU1@uni-berlin.de> <2j21dlFrvu2sU1@uni-berlin.de> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1087121537 1869 134.91.1.34 (13 Jun 2004 10:12:17 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Sun, 13 Jun 2004 10:12:17 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: g2news1.google.com comp.lang.ada:1442 Date: 2004-06-13T10:12:17+00:00 List-Id: Roland Illig 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;