Re: [fpc-devel] Abstract functons with parameters on classes
ik wrote: Assume I have the same API calls for different things in classes, and the only difference me as someone who uses this API is to use the right class, but all of the other code is not changed, except specific calls ... You would not only need to know the "right" class, but also the right parameter set belonging to the call. This sort of screws the whole object-orientation. Now I know that Parent do not know anything about a child, but can I make it "virtual" in the way the parameters is created in the child way, and do it as part of the abstract ? You can do that by using a more generic parameter (array of const, or even a class type), but what's the point? A caller still needs to know the correct parameter set and the callee needs to evaluate if it has given the correct one for its particular instance. That's like implementation "generics" as case-statement: case Argument of 1: Do_1; 2: Do_2; ... You can do that, but I would strongly recommend, you don't. It's stupid, believe me. Everytime you add something, you have to reimplement all the checks. I've seen such code. It just doesn't work out. Vinzent. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Abstract functons with parameters on classes
On 7/27/06, Peter Vreman <[EMAIL PROTECTED]> wrote: > On 7/27/06, Jonas Maebe <[EMAIL PROTECTED]> wrote: >> >> On 27 Jul 2006, at 17:49, ik wrote: >> >> > The issue is that TA is an abstract class, while TA2 and anything else >> > will inherit this class, but will implement different things/ways of >> > things ... so the "fnc" function will need a different structure on >> > each class. >> >> What is the use of having an abstract fnc in the base class? I don't >> understand what you want to do. For calling these differently >> structured "overloads" you have to typecast your class to TA2 or so >> anyway, unless you declare all these variants also as virtual >> abstract methods in your base class (in which case your problem is >> immediately solved, but I don't really see the use of that because >> you can't have generic code when calling any of these methods anyway). > > My wish to to make sure that the classes have the same function names, > that only it's parameters are different depending on the need > That is ofcourse not possible because if you call a (virtual) method of TA then the doesn't know anything about TA2. That is how the object model works. You know things of the parent classes. But a parent class doesn't know anything about it's children. OK, now I understand that I was not clear enough ;) Assume I have the same API calls for different things in classes, and the only difference me as someone who uses this API is to use the right class, but all of the other code is not changed, except specific calls ... Now I know that Parent do not know anything about a child, but can I make it "virtual" in the way the parameters is created in the child way, and do it as part of the abstract ? As I understand from previous knowledge and from your answer, it it impossible ... I guess I will have to wait for templates in order to have such way ... until then I will not use abstract declaration of such functions at all... Thanks, Ido ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Abstract functons with parameters on classes
> On 7/27/06, Jonas Maebe <[EMAIL PROTECTED]> wrote: >> >> On 27 Jul 2006, at 17:49, ik wrote: >> >> > The issue is that TA is an abstract class, while TA2 and anything else >> > will inherit this class, but will implement different things/ways of >> > things ... so the "fnc" function will need a different structure on >> > each class. >> >> What is the use of having an abstract fnc in the base class? I don't >> understand what you want to do. For calling these differently >> structured "overloads" you have to typecast your class to TA2 or so >> anyway, unless you declare all these variants also as virtual >> abstract methods in your base class (in which case your problem is >> immediately solved, but I don't really see the use of that because >> you can't have generic code when calling any of these methods anyway). > > My wish to to make sure that the classes have the same function names, > that only it's parameters are different depending on the need > That is ofcourse not possible because if you call a (virtual) method of TA then the doesn't know anything about TA2. That is how the object model works. You know things of the parent classes. But a parent class doesn't know anything about it's children. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Abstract functons with parameters on classes
On 7/27/06, Jonas Maebe <[EMAIL PROTECTED]> wrote: On 27 Jul 2006, at 17:49, ik wrote: > The issue is that TA is an abstract class, while TA2 and anything else > will inherit this class, but will implement different things/ways of > things ... so the "fnc" function will need a different structure on > each class. What is the use of having an abstract fnc in the base class? I don't understand what you want to do. For calling these differently structured "overloads" you have to typecast your class to TA2 or so anyway, unless you declare all these variants also as virtual abstract methods in your base class (in which case your problem is immediately solved, but I don't really see the use of that because you can't have generic code when calling any of these methods anyway). My wish to to make sure that the classes have the same function names, that only it's parameters are different depending on the need For example, loading from a file, or getting information from a stream... every child class will do something else that will result in the same type of action (like TBitmap, TJpeg etc.. that are based on the same abstract, but does something different in order to allow us to work with the image type). Jonas Ido ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Abstract functons with parameters on classes
On 27 Jul 2006, at 17:49, ik wrote: The issue is that TA is an abstract class, while TA2 and anything else will inherit this class, but will implement different things/ways of things ... so the "fnc" function will need a different structure on each class. What is the use of having an abstract fnc in the base class? I don't understand what you want to do. For calling these differently structured "overloads" you have to typecast your class to TA2 or so anyway, unless you declare all these variants also as virtual abstract methods in your base class (in which case your problem is immediately solved, but I don't really see the use of that because you can't have generic code when calling any of these methods anyway). Jonas ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] Abstract functons with parameters on classes
On Thursday 27 July 2006 17:49, ik wrote: > Hi all, > > Is there a way to do the following ? > ... > {$MODE OBJFPC} > type > TA = class > public > function fnc : Boolean; virtual; abstract; > end; > > > TA2 = class (TA) > public > function fnc (const a : Boolean) : Boolean; override; > end; > ... Maybe the "overload" keyword works between classes? I don't know, I haven't tried it yet. You could. -- Regards, Christian Iversen ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
[fpc-devel] Abstract functons with parameters on classes
Hi all, Is there a way to do the following ? ... {$MODE OBJFPC} type TA = class public function fnc : Boolean; virtual; abstract; end; TA2 = class (TA) public function fnc (const a : Boolean) : Boolean; override; end; ... The issue is that TA is an abstract class, while TA2 and anything else will inherit this class, but will implement different things/ways of things ... so the "fnc" function will need a different structure on each class. Please note that the above way does not work for me (maybe because I have more then one override for the "fnc" function ?). Thanks, Ido ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel