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.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,59b48da8620e604f X-Google-Attributes: gid103376,public From: johnherro@aol.com (John Herro) Subject: Re: Example of object oriented Ada95 requested! Date: 1996/01/08 Message-ID: <4cr0ol$ojr@newsbf02.news.aol.com>#1/1 X-Deja-AN: 134430672 sender: root@newsbf02.news.aol.com references: organization: America Online, Inc. (1-800-827-6364) newsgroups: comp.lang.ada Date: 1996-01-08T00:00:00+00:00 List-Id: Arcadio A Sincero (cabal@TerpTavern.umd.edu) is using Ada-Tutr and asking about examples of encapsulation, inheritance, and polymorphism. Dear Arcadio, You're absolutely right about the package being Ada's primary mechanism for encapsulation. As you get into the tutorial, you'll learn how packages help contain the effects of changes to one part of the program; this is even more true when you get into private types. The full advantages of inheritance and polymorphism (OOP) don't really come into play until the project gets pretty large. In my tutorial, I try to keep the examples fairly simple. While I expect the user to grasp the examples, I only hint at the _advantages_ of OOP. Admittedly, I don't really expect the user to grasp the advantages until he or she has worked with larger projects. Inheritance usually (but not always) refers to child packages and heirarchical libraries. Sometimes the word inheritance is also used with derived types, which were available in Ada 83. For example, if we write type Count is new Integer; then type Count _inherits_ the operations that Ada already knows for Integer, such as addition, subtraction, etc. That use of the word inheritance has little to do with OOP. When used with heirarchical libraries, inheritance refers to the fact that a child package inherits resources from the parent, and can add additional resources of its own. The advantage is that the child package can be modified and recompiled, without need to recompile the parent and the program units that "with" only the parent. On a large project, this can save not only a lot of recompilation time, but a lot of time spent on program redevelopment as the requirements are refined or changed. Polymorphism (meaning many forms) usually refers to tagged record types. The example in the tutorial of tagged type Date (having fields Day, Month, and Year) and type Complete_Date (adding a day-of-week field to type Date) is an example of polymorphism. The advantages include the fact that we can create heterogeneous linked lists, trees, and other structures (containing Dates and Complete_Dates), and that we can have the system decide at run time which of several subprograms to call, depending on the type of an object, which might be pointed to by an access type. This feature is called dynamic dispatching. Again the advantages show up in larger projects. The code in your message is an excellent example of child packages, which has to do with inheritance. (Your code may have a few minor syntax errors, such as "procedure HardDrive;" instead of "procedure HardDrive is" in the package body.) An example of polymorphism would involve _types_, such as the tagged type Date in the tutorial. I hope this helps. By the way, I'm presently working on a minor update of Ada Tutor, which I expect to make available on the Web and by FTP. I'll announce it here as soon as it's released. - John Herro Software Innovations Technology