Mime-Version: |
1.0 |
Content-Type: |
text/plain; charset="iso-8859-1" |
X-To: |
|
Date: |
Wed, 14 Oct 1998 13:11:55 -0700 |
Reply-To: |
|
Subject: |
|
From: |
|
Content-Transfer-Encoding: |
7bit |
Sender: |
|
Parts/Attachments: |
|
|
John Harbaugh wrote:
>This illustrates a fundamental advantage of Ada: It is difficult to
>write correct programs that have typos.
I agree in general, but there is one pitfall in the case of OOP (which by
the way is not unique to Ada). If you misspell the name of a subprogram
intended to override an otherwise implicitly inherited operation, then you
do not override it even though you think you have. Example:
package Student_Pkg is
type Student is tagged private;
type Student_Class_Ref is access Student'Class;
function Financial_Aid (Item : Student) return Natural;
...
end Student_Pkg;
with Student_Pkg; use Student_Pkg;
package Athlete_Pkg is
type Athlete is new Student with private;
function Financal_Aid( Item : Athlete) return Natural;
-- Note mistake in spelling name of function
...
end Athlete_Pkg;
with Student_Pkg, Athlete_Pkg;
use Student_Pkg, Athlete_Pkg;
procedure Example is
X : Student_Class_Ref := new Athlete;
N : Natural;
begin
...
N := Financial_Aid( X.all ); --(*)
end Example;
The dynamic binding at (*) invokes the Student version of Financial_Aid,
which is probably not what was intended. To some extent the need to repeat
the subprogram specification in the package body reduces the risk of this
effect, since maybe the typo will be spotted if it appears twice, but it is
still a potential "gotcha".
Regards,
Ben Brosgol
[log in to unmask]
|
|
|