comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: how to import a package
Date: Mon, 11 Dec 2006 20:28:16 GMT
Date: 2006-12-11T20:28:16+00:00	[thread overview]
Message-ID: <Abjfh.1093829$084.864157@attbi_s22> (raw)
In-Reply-To: <1165846777.475130.199390@f1g2000cwa.googlegroups.com>

markww wrote:
> 
>     procedure Add_Record(GenericData : PERSON_REC) is
>     Temp : gNode.Node_Ptr;
>     begin
> 
>         Temp := new gNode.Node;
>         Temp.Data := GenericData;
>     end Add_Record;

This leaks memory.

Others have discussed the solution to your specific problem, but I think 
what you're missing is the general mind-set that a type definition and 
the operations on that type should be encapsulated in a package. So far, 
you only have 1 operation (Add_Record), but in a generally useful 
linked-list package you'd probably have a lot more. Those operations 
should be in the package; then, whenever you instantiate the package, 
you get the operations.

This concept, encapsulation of data and their operations (usually with 
hiding of the data's structure), is called "object orientedness". In 
many languages, this design concept is mixed up with the implementation 
concept of programming by extension (incorrectly called OOP); for 
example, in C++, you get both from the "class" construct. In Ada, the 2 
are separate.

At this point, you might find it instructive to look at some existing 
linked-list packages, such as the one in the Ada-0X container library, 
or the ones in the PragmAda Reusable Components

http://pragmada.home.mchsi.com/

or many of the component libraries you can find at adapower.com or 
adaworld.com.

-- 
Jeff Carter
"Blessed is just about anyone with a vested interest in the status quo."
Monty Python's Life of Brian
73



  parent reply	other threads:[~2006-12-11 20:28 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06  2:14 how to import a package markww
2006-12-06  3:06 ` Adam Beneschan
2006-12-06  3:34   ` markww
2006-12-06  9:18     ` Simon Wright
2006-12-06 19:47 ` Jeffrey R. Carter
2006-12-06 23:56   ` markww
2006-12-07  1:18     ` Björn Persson
2006-12-07  1:26     ` Brian May
2006-12-07  4:14       ` markww
2006-12-07  4:40         ` Brian May
2006-12-07  9:32           ` Stuart
2006-12-07 11:21             ` Jean-Pierre Rosen
2006-12-11  6:16               ` markww
2006-12-11  6:50                 ` markww
2006-12-11  9:40                   ` Georg Bauhaus
2006-12-11 14:19                     ` markww
2006-12-11 15:03                       ` Dmitry A. Kazakov
2006-12-11 16:22                       ` Adam Beneschan
2006-12-11 20:28                       ` Jeffrey R. Carter [this message]
2006-12-12  3:19                         ` markww
2006-12-12  3:31                           ` Jeffrey R. Carter
2006-12-12  9:03                           ` Stuart
2006-12-12 10:56                           ` Georg Bauhaus
2006-12-11  7:00                 ` Simon Wright
2006-12-07  4:06     ` Jeffrey R. Carter
replies disabled

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