home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / ada / 2351 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  1.8 KB

  1. Path: sparky!uunet!sps!jot
  2. From: jot@sps.com (Joe Tallet)
  3. Newsgroups: comp.lang.ada
  4. Subject: Re: Type Extensions VS Classes (was Re: Object Oriented Ada...)
  5. Message-ID: <330@sps.com>
  6. Date: 11 Aug 92 20:15:08 GMT
  7. References: <1992Aug4.172639.17168@ichips.intel.com> <BEVAN.92Aug4213057@otter.cs.man.ac.uk> <9222000.23050@mulga.cs.mu.OZ.AU>
  8. Organization: Software Productivity Solutions, Inc (SPS), Melbourne, FL, USA
  9. Lines: 57
  10.  
  11. In article <9222000.23050@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  12. >Does Ada-9X have any concept similar to C++'s abstract base classes?
  13. >
  14. >For example, in C++ I might have something like
  15. >
  16. >    class Shape {
  17. >    public:
  18. >        virtual void draw() = 0;
  19. >        virtual ~Shape {}
  20. >    };
  21. >
  22. >    class Circle: public shape { virtual void draw() { ... } };
  23. >    class Square: public shape { virtual void draw() { ... } };
  24. >    // etc.
  25. >
  26. >How would you do this in Ada-9X?
  27. >
  28.  
  29. . . . use Classic-Ada PDL . . .
  30.  
  31. ----------------
  32.   class Shape is
  33.     -- Used to define behavior common to both Circle and Square.
  34.     -- If there is no common behavior then there is no need to have it here.
  35.     -- An abstract class has no methods to create instances.
  36.     instance method Draw;
  37.     instance method Finalize;
  38.   end Shape;
  39.  
  40. ----------------
  41.   class Circle is
  42.     superclass Shape;
  43.     method Create (New_Object : out Object_Id);
  44.     instance method Draw;
  45.     instance method Finalize;
  46.     instance method Delete;
  47.   end Circle;
  48.  
  49. ----------------
  50.   class Square is
  51.     superclass Shape;
  52.     method Create (New_Object : out Object_Id);
  53.     instance method Draw;
  54.     instance method Finalize;
  55.     instance method Delete;
  56.   end Square;
  57.  
  58. ----------------
  59.   -- No need to 'with' or 'use' the destination object.
  60.   procedure Client (A_Shape : Object_Id) is
  61.   begin
  62.     send (A_Shape, Draw);
  63.   end Client;
  64.  
  65.  
  66. jot
  67.  
  68.