Abstract and protected methods
Posted
#1
(In Topic #825)
Trainee
Posted
Guru

Witchi said
by Witchi » Thursday 24th February 2022 1:25pm
Are there such things like abstract methods or protected methods within Gambas?
Wow! I had to look that up. I am still not sure what it all means, but you can 'Inherit' items into a class and add methods, variables and events, if that helps. What are you trying to achieve?
Posted
Regular

Witchi said
Are there such things like abstract methods or protected methods within Gambas?
No. If you need abstract method, you can do this:
Methods are only private or public.
Gambas, like its parent Visual Basic, is designed for rapid desktop GUI developing. It has poor OOP capabilities, but enough for simple desktop apps and thick clients.
Posted
Trainee
cogier said
Witchi said
by Witchi » Thursday 24th February 2022 1:25pm
Are there such things like abstract methods or protected methods within Gambas?
Wow! I had to look that up. I am still not sure what it all means, but you can 'Inherit' items into a class and add methods, variables and events, if that helps. What are you trying to achieve?
Abstract methods must be re-implemented within sub-classes, so the base class can call it, but the code comes from the subclass. So you can implement different things in every subclass, which the base class can call.
Protected methods are methods which are only accessible from sub-classes. Public methods are visible for every other class, private methods are only visible within its own class. So a way between both are protected methods, which cannot be executed by external code, but from the own class and sub-classes.
Both are essential things for OOP.
Posted
Trainee
AMUR-WOLF said
That is not the same. Here I can override the Method(), but if I call it from the declaring class, it won't execute method overridden by the subclass. You can see that within the attached example project. I have to define a lot of things as public (instead of protected) in the base class and also set these properties from within the subclass constructor _new() to change the behaviour of the base class for every sub-class.
example project for abstract methods
Posted
Regular

Witchi said
That is not the same. Here I can override the Method(), but if I call it from the declaring class, it won't execute method overridden by the subclass. You can see that within the attached example project. I have to define a lot of things as public (instead of protected) in the base class and also set these properties from within the subclass constructor _new() to change the behaviour of the base class for every sub-class.
Yes, that is not the same. Classes in Gambas are 100% realistic and 100% complete. Each base class is ready to use, so, if you invoke a method from base class it behaves as it did in base class. If you want to change this behaviour, you still can do it, but explicitly:
Also, when you create an object of child class, a constructor of base class is invoked first (unlike in Java).
Abstractions are not essential for OOP, but help to build huge applications with heavy architecture. Sometimes I think that idea of 100% realism and 100% completeness is Zen. But I really need protected members, interfaces and generics.
Posted
Regular

Probably you can achieve your aims via design pattern "Strategy":
Posted
Trainee
Is there a guide for Gambas object model? Like a document which compares OO things in Gambas with other languages and some work-arounds? I have a lot of questions in that way. So I find the constructor parameter thing very strange in Gambas or what is with re-declaration of variables in sub-classes? Such things will be tricky, if you have already develop apps in C++, Java or PHP.
1 guest and 0 members have just viewed this.


