virtual methods 
Author Message
 virtual methods

Just trying out the ISO M2 oop extensions, and am unclear on the
implementation of static/virtual methods. Is it the case that any method is
virtual, unless it includes the OVERRIDE keyword?

Thanks,
James



Sat, 08 Feb 2003 03:00:00 GMT  
 virtual methods
All methods are virtual (called via a "method table").

The exception to this are methods declared only in the IMPLEMENTATION of a
module for a class defined in the DEFINITION. These "methods" are only
visible to code within the implementation module if the method is revealed.

--
Norman Black
Stony Brook Software
the reply, fubar => ix.netcom


Quote:
> Just trying out the ISO M2 oop extensions, and am unclear on the
> implementation of static/virtual methods. Is it the case that any method
is
> virtual, unless it includes the OVERRIDE keyword?

> Thanks,
> James



Sat, 08 Feb 2003 03:00:00 GMT  
 virtual methods


Quote:
> All methods are virtual (called via a "method table").

> The exception to this are methods declared only in the IMPLEMENTATION of a
> module for a class defined in the DEFINITION. These "methods" are only
> visible to code within the implementation module if the method is

revealed.

Interesting. Even tho' it may be revealed, it still seems more private than
static. Is the following example correct (pardon the pseudocode)?

TBob:             class
                       procedure CutHair();
                     end

TBobJr:           class
                        inherit Bob;
                        procedure CutHair();
                     end

procedure BobBarber(Bob: TBob);
BEGIN
  Bob.CutHair();
END BobBarber;

BobBarber(Bob); (* Cuts Bob's hair *)
BobBarber(BobJr); (* Cuts BobJr's hair *)

TRalph:          class
                       procedure CutHair();
                     end

TRalphJr:           class
                        inherit Ralph;
                        OVERRIDE procedure CutHair();
                     end

procedure RalphBarber(Ralph: TRalph);
BEGIN
  Ralph.CutHair();
END RalphBarber;

RalphBarber(Ralph);          (* Cuts Ralph's hair *)
RalphBarber(RalphJr);        (* Still cuts Ralph's hair, right? *)

Thanks,
James



Sat, 08 Feb 2003 03:00:00 GMT  
 virtual methods
The first example is not valid, as you must override the inherited
procedure. Also your examples did not specify what portions of the class
declarations were in a DEF/IMP, IMP only.

In the second example the procedure RalphBarber does not know who's hair he
is cutting. The parameter is of the base class which can hold the base class
or any inherited class. It is not known if any child of the base has
overridden the CutHair method.

If you want to call a method from a class specifically you can qualify the
call with the class type name. When this is done the method is search from
the specified class to the ancestors for the method in question. The first
match is used.

--
Norman Black
Stony Brook Software
the reply, fubar => ix.netcom


Quote:



> > All methods are virtual (called via a "method table").

> > The exception to this are methods declared only in the IMPLEMENTATION of
a
> > module for a class defined in the DEFINITION. These "methods" are only
> > visible to code within the implementation module if the method is
> revealed.

> Interesting. Even tho' it may be revealed, it still seems more private
than
> static. Is the following example correct (pardon the pseudocode)?

> TBob:             class
>                        procedure CutHair();
>                      end

> TBobJr:           class
>                         inherit Bob;
>                         procedure CutHair();
>                      end

> procedure BobBarber(Bob: TBob);
> BEGIN
>   Bob.CutHair();
> END BobBarber;

> BobBarber(Bob); (* Cuts Bob's hair *)
> BobBarber(BobJr); (* Cuts BobJr's hair *)

> TRalph:          class
>                        procedure CutHair();
>                      end

> TRalphJr:           class
>                         inherit Ralph;
>                         OVERRIDE procedure CutHair();
>                      end

> procedure RalphBarber(Ralph: TRalph);
> BEGIN
>   Ralph.CutHair();
> END RalphBarber;

> RalphBarber(Ralph);          (* Cuts Ralph's hair *)
> RalphBarber(RalphJr);        (* Still cuts Ralph's hair, right? *)

> Thanks,
> James



Sun, 09 Feb 2003 03:00:00 GMT  
 virtual methods

Quote:
> In the second example the procedure RalphBarber does not know who's hair
he
> is cutting. The parameter is of the base class which can hold the base
class
> or any inherited class. It is not known if any child of the base has
> overridden the CutHair method.

So is it the case that all methods are not implicitly virtual, but must have
the OVERRIDE attribute to be virtual. IOW, other languages use the VIRTUAL
attribute to support polymorphism. In OOM2, does OVERRIDE provide the same
function?

Thanks,
James



Sun, 09 Feb 2003 03:00:00 GMT  
 virtual methods
As stated previously all methods are virtual, with exception noted about IMP
modules. OVERRIDE just lets you override an existing inherited method.
If you use OVERRIDE and the method was not inherited it is a compilation
error.
If you define a method without OVERRIDE and you inherited such a method it
is a compilation error.

--
Norman Black
Stony Brook Software
the reply, fubar => ix.netcom


Quote:
> > In the second example the procedure RalphBarber does not know who's hair
> he
> > is cutting. The parameter is of the base class which can hold the base
> class
> > or any inherited class. It is not known if any child of the base has
> > overridden the CutHair method.

> So is it the case that all methods are not implicitly virtual, but must
have
> the OVERRIDE attribute to be virtual. IOW, other languages use the VIRTUAL
> attribute to support polymorphism. In OOM2, does OVERRIDE provide the same
> function?

> Thanks,
> James



Mon, 10 Feb 2003 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. virtual method call faster that non-virtual method?

2. Better OOP, Part 8 -- Inheritance and virtual methods

3. (Pure) virtual methods

4. Calling a Virtual Method in TASM

5. ASM Objects / Virtual Methods

6. Classes, virtual methods ?

7. Virtual Methods? Help!

8. "pure virtual method called" -- What am I doing wrong???

9. On equality and other binary methods (was: Meyer on virtual types)

10. Virtual Schooling a Virtual Reality?

11. Virtual Schooling a Virtual Reality?

12. Virtual 8086 Mode/Virtual Machine Monitor (VMM)

 

 
Powered by phpBB® Forum Software