home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sps!jot
- From: jot@sps.com (Joe Tallet)
- Newsgroups: comp.lang.ada
- Subject: Re: Type Extensions VS Classes (was Re: Object Oriented Ada...)
- Message-ID: <330@sps.com>
- Date: 11 Aug 92 20:15:08 GMT
- References: <1992Aug4.172639.17168@ichips.intel.com> <BEVAN.92Aug4213057@otter.cs.man.ac.uk> <9222000.23050@mulga.cs.mu.OZ.AU>
- Organization: Software Productivity Solutions, Inc (SPS), Melbourne, FL, USA
- Lines: 57
-
- In article <9222000.23050@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- >Does Ada-9X have any concept similar to C++'s abstract base classes?
- >
- >For example, in C++ I might have something like
- >
- > class Shape {
- > public:
- > virtual void draw() = 0;
- > virtual ~Shape {}
- > };
- >
- > class Circle: public shape { virtual void draw() { ... } };
- > class Square: public shape { virtual void draw() { ... } };
- > // etc.
- >
- >How would you do this in Ada-9X?
- >
-
- . . . use Classic-Ada PDL . . .
-
- ----------------
- class Shape is
- -- Used to define behavior common to both Circle and Square.
- -- If there is no common behavior then there is no need to have it here.
- -- An abstract class has no methods to create instances.
- instance method Draw;
- instance method Finalize;
- end Shape;
-
- ----------------
- class Circle is
- superclass Shape;
- method Create (New_Object : out Object_Id);
- instance method Draw;
- instance method Finalize;
- instance method Delete;
- end Circle;
-
- ----------------
- class Square is
- superclass Shape;
- method Create (New_Object : out Object_Id);
- instance method Draw;
- instance method Finalize;
- instance method Delete;
- end Square;
-
- ----------------
- -- No need to 'with' or 'use' the destination object.
- procedure Client (A_Shape : Object_Id) is
- begin
- send (A_Shape, Draw);
- end Client;
-
-
- jot
-
-