View Full Version : PPL - Polymorphism
Vever
09-24-2006, 08:49 PM
Hi,
I've started to learn OOP and I'd like to use polymorphism in PPL, but I cannot override method of base class in derived class. Is there any other way how to do it? I need to use base class with common function calling other function contained in derived classes (with same name in all of them, of couse ;) ).
THX,
Vever
kornalius
09-25-2006, 01:29 AM
As of now it's not possible. I will look into it and see if it's easily feasible without too much work. I will let you know tomorrow.
Vever
09-25-2006, 06:23 AM
Thank you, I can solve it but the solution isn't flexible enough. I can use the base class with one common function as separate one with case ... structure creating new object from different classes according to a situation. Then I can call the common function from the object. But I have to update case structure when I want to add a new class to my code :(( .
Vever
kornalius
09-25-2006, 04:42 PM
Here is an update on polymorphism in v1.02:
#class base
proc test
ShowMessage("base");
end;
#endclass
#class child
proc test
ShowMessage("child");
end;
#endclass
proc main
#object child o$
o.test;
a$ = base(o$);
a.test;
child(a$);
a.test;
base(o$).test;
#object base o2$
o2.test;
end;
This code runs perfectly.
Vever
09-25-2006, 06:35 PM
To kornalius:
thank you for your sample, but I'm not sure I'm familiar with this code enough. Could you comment it, please? At least results. I cannot try it ;) .
I need sometning like this:
#class base
Text2$ = "";
func Cypher (Num_OT$)
end;
public func Code (Text1$)
Len_OT$ = Length (Text1$);
for (i$, 0, Len_OT$-1, 1)
Char_OT$ = Text1$[i$];
Char_CT$ = Cypher (Char_OT$);
Text2$ = Text2$ + CHR(Char_CT$);
end;
return (Text2$);
end;
#endclass
#class base child1
override func Cypher (Num_OT$) // Overrides empty Cypher func from base class
Num_CT$ = Num_OT$ - 2;
return (Num_CT$);
end;
#endclass
#class base child2
override func Cypher (Num_OT$) // Overrides empty Cypher func from base class
Num_CT$ = Num_OT$ + 2;
return (Num_CT$);
end;
#endclass
proc Main;
#object child1 obj1$
#object child2 obj2$
Res1$ = obj1.Code("DEF");
Res2$ = obj2.Code("DEF");
ShowMessage (Res1$); // Prints CDE
ShowMessage (Res2$); // Prints FGH
end;
kornalius
09-25-2006, 07:30 PM
My exemple showed calling base classes functions from outside not inside a class member.
Btw remove the override it's not needed in class definition.
Your code works perfectly in 1.02.
Polymorphism wasn't fully implemented before. The results are:
0BCD
0FGH
Vever
09-25-2006, 09:17 PM
That is great !amazed !!! I've written it's worth waiting for 1.02 :p .
Vever
kornalius
09-25-2006, 09:25 PM
Oh yes trust me. It's going to be what 1.0 should have been.
Vever
09-25-2006, 09:32 PM
1.0 is usually supposed to be "mass tested beta". I think PPL is going to be almost perfect in 1.02 and it's very good. I'm looking forward to it (it'll solve my problem with polymorphism too! !lol ).
Thanks for your work,
Vever
Vever
10-03-2006, 10:39 AM
I was in Dolomites during last week so I didn't test polymorphism in 1.02 but it works in 1.03. Thank you!
Vever
10-03-2006, 10:42 AM
Could you delete two of those replies? I don't understand it, but I managed to send it three times :O . THX.
kornalius
10-03-2006, 11:43 AM
Done.
I am happy that polymorphism is working. Anything to make PPL is better is a plus in my book.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.