From: Martin Krischik <martin@krischik.com>
Subject: Re: Ada 2005?
Date: Sat, 18 Dec 2004 09:51:48 +0100
Date: 2004-12-18T09:51:48+01:00 [thread overview]
Message-ID: <1258920.S9jBcL00t9@linux1.krischik.com> (raw)
In-Reply-To: 1103344064.372396.51420@c13g2000cwb.googlegroups.com
conradwt@runbox.com wrote:
> Hi, will Ada support keyword class for designing and implementing
> classes? For example, I'm forced to convert the following C++ class in
> Ada as follows:
>
> // C++
>
> class A_Device {
>
> public:
>
> A_Device( char*, int, int );
>
> char* Name( void );
>
> int Major( void );
>
> int Minor( void );
>
> protected:
>
> char* name;
>
> int major;
>
> int minor;
> };
>
> // Now, if I need to interact with the, this class I can do the
> // following:
>
> void main(void) {
>
> A_Device aDevice = new A_Device( "Test", 1, 1 );
>
> cout << aDevice.Name() << endl;
> cout << aDevice.Major() << endl;
> cout << aDevice.Minor() << endl;
>
> }
>
> // Ada
>
> package Devices is
>
> type Device is tagged private;
>
> type Device_Type is access private;
You do to much pointer work! Ada does not need that much pointer work! Read:
http://en.wikibooks.org/wiki/Programming:Ada:OO#The_class-wide_type
> function Create( Name : String,
> Major : Integer,
> Minor : Integer ) return Device_Type;
>
> function Name( this : Device_Type ) return String;
You did the equivalent of:
class Device
{
static char*
Name(Device* this);
}
A "static" class member will not dispatch! You should have done:
function Name( this : in Device) return String;
or
function Name( this : in out Device) return String;
Read:
http://en.wikibooks.org/wiki/Programming:Ada:OO#Primitive_Operations
>
> function Major( this : Device_Type ) return Integer;
>
> function Minor( this : Device_Type ) return Integer;
>
> private
>
> type Device is tagged
>
> record
>
> name : String(1..20);
> major: Integer;
> minor: Integer;
>
> end record;
>
> end Devices;
>
> Now, interact with Ada package I would need to do the following:
>
> procedure main
>
> aDevice : Device_Type := Devices.Create( "Test", 1, 1 );
>
> begin
>
> Put_Line( Name( aDevice ) );
> Put_Line( Major( aDevice ) );
> Put_line( Minor( aDevice ) );
> end main;
>
> It seems that I'm trying to mimic the behavior of a OO language in a
> procedural language when converting C++ to Ada. Is this correct?
No! Ada has OO - but you have not read enough tutorials to know how Ada's OO
works. Keep going and you get there!
> If
> so, why doesn't Ada have OO contructs similar to C++,
> Java, Eiffel, and Smalltalk to name a few where one passes a message to
> an instance of a class?
Ada does have these features! The difference is that Ada is package
(namespace) centric and not record (struct) centric. In fact a Ada class
need to be defined inside a package (namespace)!
It is not uncomme to declare a classes like this:
package Parent_Class
is
type Object is tagged
record
.....
end record;
end Class_Name;
with Parent_Class;
package Child_Class
is
type Object
is new
Parent_Class.Object
with record
.....
end record;
end Class_Name;
> Will this be something in Ada 2005 because I
> have been able to find a good overview of the language to date?
Only interfaces are added to Ada 2005 - everything else is allready there.
With Rergards
Martin
--
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com
next prev parent reply other threads:[~2004-12-18 8:51 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-18 4:27 Ada 2005? conradwt
2004-12-18 8:08 ` Martin Dowie
2004-12-20 20:06 ` conradwt
2004-12-21 6:51 ` Martin Dowie
2004-12-18 8:47 ` christov
2004-12-19 3:28 ` Randy Brukardt
2004-12-19 19:11 ` christov
2004-12-19 22:07 ` Ada User Journal (was: Re: Ada 2005?) Dirk Craeynest
2004-12-19 22:34 ` Ada User Journal Florian Weimer
2004-12-20 9:19 ` Martin Krischik
2004-12-20 11:02 ` Florian Weimer
2004-12-20 12:22 ` Thomas Hühn
2004-12-27 13:16 ` Florian Weimer
2004-12-21 0:15 ` Ada 2005? David Botton
2004-12-18 8:51 ` Martin Krischik [this message]
2004-12-18 16:03 ` Dmitry A. Kazakov
2004-12-20 18:49 ` conradwt
2004-12-20 20:10 ` Dmitry A. Kazakov
2004-12-20 23:44 ` jayessay
2004-12-21 1:26 ` Alexander E. Kopilovich
2004-12-21 8:31 ` Dmitry A. Kazakov
2004-12-21 17:24 ` jayessay
2004-12-21 8:11 ` Dmitry A. Kazakov
2004-12-21 17:10 ` jayessay
2004-12-21 17:12 ` Dmitry A. Kazakov
2004-12-21 21:42 ` jayessay
2004-12-22 8:55 ` Dmitry A. Kazakov
2004-12-22 18:02 ` jayessay
2004-12-22 19:10 ` Dmitry A. Kazakov
2004-12-23 18:09 ` jayessay
2004-12-24 9:41 ` Dmitry A. Kazakov
2004-12-27 17:09 ` jayessay
2004-12-27 19:44 ` Dmitry A. Kazakov
2004-12-27 21:51 ` Georg Bauhaus
2004-12-28 9:56 ` Dmitry A. Kazakov
2004-12-28 17:56 ` jayessay
2004-12-28 17:48 ` jayessay
2004-12-28 17:36 ` jayessay
2004-12-21 8:33 ` Martin Krischik
2004-12-21 15:34 ` jimmaureenrogers
2004-12-21 15:53 ` Martin Krischik
2004-12-22 9:34 ` Larry Kilgallen
2004-12-22 11:01 ` Martin Krischik
2004-12-22 12:52 ` Larry Kilgallen
2004-12-22 16:38 ` Martin Krischik
2004-12-23 23:05 ` conradwt
2004-12-24 9:24 ` Pascal Obry
2004-12-24 9:59 ` Martin Krischik
2004-12-18 19:31 ` Jeffrey Carter
2004-12-20 18:55 ` conradwt
2004-12-20 23:53 ` Jeffrey Carter
2004-12-21 0:25 ` David Botton
2004-12-19 3:16 ` Brian May
2004-12-20 23:38 ` jayessay
2004-12-21 21:42 ` Brian May
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox