LucaMs Expert Licensed User Longtime User Sep 17, 2021 #3 aeric said: 3 levels ? ? Click to expand... at least!
AnandGupta Expert Licensed User Longtime User Sep 17, 2021 #4 I too want it. Have the habit of it in other languages.
aeric Expert Licensed User Longtime User Sep 17, 2021 #5 I seen in previous posts Erel mentioned that Composition is preferred and supported. I only started to use B4J so I don’t know how Inheritance is useful. I don’t really use Inheritance /SubClassing in VB6 or VB.NET. Even Polymorphism I don’t remember when was the last time I use CallSub.
I seen in previous posts Erel mentioned that Composition is preferred and supported. I only started to use B4J so I don’t know how Inheritance is useful. I don’t really use Inheritance /SubClassing in VB6 or VB.NET. Even Polymorphism I don’t remember when was the last time I use CallSub.
LucaMs Expert Licensed User Longtime User Sep 17, 2021 #6 aeric said: I seen in previous posts Erel mentioned that Composition is preferred and supported. Click to expand... "Supported" is obvious, since a class can "host" an object. About Composition... I don't understand how this can replace inheritance
aeric said: I seen in previous posts Erel mentioned that Composition is preferred and supported. Click to expand... "Supported" is obvious, since a class can "host" an object. About Composition... I don't understand how this can replace inheritance
LucaMs Expert Licensed User Longtime User Sep 18, 2021 #7 LucaMs said: About Composition... I don't understand how this can replace inheritance Click to expand... This could be one way: clsMan instance declared as public in clsEmployee (it's a bit risky but it can be done). Using "com" as a prefix (comMan - component) can be helpful.
LucaMs said: About Composition... I don't understand how this can replace inheritance Click to expand... This could be one way: clsMan instance declared as public in clsEmployee (it's a bit risky but it can be done). Using "com" as a prefix (comMan - component) can be helpful.
LucaMs Expert Licensed User Longtime User Sep 18, 2021 #8 LucaMs said: clsMan instance declared as public in clsEmployee (it's a bit risky but it can be done). Click to expand... By declaring the "parent object" public, however, you have a big problem if you want to override a member; there would be two methods with the same name, one in the child class, one in the exposed object. This problem does not exist by declaring the object as private; but in this case it will be necessary to create many "delegating" members.
LucaMs said: clsMan instance declared as public in clsEmployee (it's a bit risky but it can be done). Click to expand... By declaring the "parent object" public, however, you have a big problem if you want to override a member; there would be two methods with the same name, one in the child class, one in the exposed object. This problem does not exist by declaring the object as private; but in this case it will be necessary to create many "delegating" members.
aeric Expert Licensed User Longtime User Sep 18, 2021 #9 I am not sure I understand correctly. I rarely use classes and inheritance. Usually I work with database tables. Now I am learning to use Type keyword. Attachments InheritanceTest.zip InheritanceTest.zip 4.6 KB · Views: 237
I am not sure I understand correctly. I rarely use classes and inheritance. Usually I work with database tables. Now I am learning to use Type keyword.
aeric Expert Licensed User Longtime User Sep 18, 2021 #10 Or set the Parent class variable as Private. B4X: Sub Class_Globals Private mName As String Private mAge As Int End Sub Attachments InheritanceTest2.zip InheritanceTest2.zip 4.6 KB · Views: 242
Or set the Parent class variable as Private. B4X: Sub Class_Globals Private mName As String Private mAge As Int End Sub
LucaMs Expert Licensed User Longtime User Sep 18, 2021 #11 What you did is not use Inheritance (also because you couldn't, there is no Inheritance in B4X) but Composition. You had to write ALSO in the "child" classes the same members of the "parent" class and then from within these you called the members of the "parent" (in practice you have delegated the execution to the "parent"). That is, you did what I wrote here: LucaMs said: but in this case it will be necessary to create many "delegating" members. Click to expand...
What you did is not use Inheritance (also because you couldn't, there is no Inheritance in B4X) but Composition. You had to write ALSO in the "child" classes the same members of the "parent" class and then from within these you called the members of the "parent" (in practice you have delegated the execution to the "parent"). That is, you did what I wrote here: LucaMs said: but in this case it will be necessary to create many "delegating" members. Click to expand...
AnandGupta Expert Licensed User Longtime User Sep 21, 2021 #12 Call it inheritance, encapsulation .. etc. I have no qualms for it. What I want is, I am trying to state in below pseudo codes, Code: class line var length method draw ' draws the line of given 'length' Code: class square from line var area method draw ' draws the square of given 'length' Note, 'length' is in 'line' class and both have 'draw' methods. square class inherits line class. Now I use them as, Code: oSquare := class square() oSquare.length := 10 oSquare.draw() If we can get it in b4X then I think most of our codes will be concise and clean. I am using this type of codes in my other programming languages.
Call it inheritance, encapsulation .. etc. I have no qualms for it. What I want is, I am trying to state in below pseudo codes, Code: class line var length method draw ' draws the line of given 'length' Code: class square from line var area method draw ' draws the square of given 'length' Note, 'length' is in 'line' class and both have 'draw' methods. square class inherits line class. Now I use them as, Code: oSquare := class square() oSquare.length := 10 oSquare.draw() If we can get it in b4X then I think most of our codes will be concise and clean. I am using this type of codes in my other programming languages.