Wish Object-Oriented Programming

Star-Dust

Expert
Licensed User
Longtime User
There are ways to do that, anyway (workarounds but it is realizable).

Way 1 - pass a Map
Way 2 - pass a "custom type object" - this is better, probably.
I have already written that there are only alternative ways of polyformism, but there is no real polyformism. If we do not read the posts carefully, we repeat the same concepts.
It does not support polyformism, but somehow we can overcome this lack by creating different methods each one that supports the parameters that we need.

And it is clear that with the term Poliformism we also include other.

We are not talking about "alternative" methods to overcome what is missing on B4X, otherwise I can list how I get something similar to inheritance, polymorphism or how I get something similar to the extension of a class. But the topic is not it. He simply wondered if it was possible to implement them.

Before ik B4A existed the Map we did everything with Lists and types. With alternative methods we obtained something similar to the Map. But how much more useful it was when the Map was implemented, nobody has ever made it clear that it was not needed or that they could do without it. Now we also have a collection, an even more powerful library.

As long as it is missing we are looking for alternative methods, but it does not mean that it would not be necessary to have an implementation in language
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
1590924980514.png


Way 2 - pass a "custom type object" - this is better, probably.
B4X:
Sub Process_Globals
    Type tAreaParam1(Base As Double, Altezza As Double)
    Type tAreaParam2(X1 As Double, Y1 As Double, _
                     X2 As Double, Y2 As Double, _
                     X3 As Double, Y3 As Double _
                    )
End Sub

Public Sub Area(Param As Object) As Double
    Dim Result As Double
 
    If Param Is tAreaParam1 Then
        Dim AreaParam1 As tAreaParam1 = Param
        Result = AreaParam1.Base * AreaParam1.Altezza * 0.5
    Else If Param Is tAreaParam2 Then
        Dim AreaParam2 As tAreaParam2 = Param
        Result = 0.5 * (AreaParam2.x1 * AreaParam2.y2 _
                      + AreaParam2.y1 * AreaParam2.x3 _
                      + AreaParam2.x2 * AreaParam2.y3 _
                      - AreaParam2.x3 * AreaParam2.y2 _
                      - AreaParam2.y3 * AreaParam2.x1 _
                      - AreaParam2.x2 * AreaParam2.y1)
    End If
 
    Return Result
End Sub

Please note the cleanliness, the legibility thanks to the indentations 😎😁
 
Last edited:

Toky Olivier

Active Member
Licensed User
Longtime User
If I were to add all the features listed in the first post, it will be the end of B4X as a RAD programming language. It would have been Java with different syntax.
It will be a very big "+" if you implement them and I'm sure I won't be the end of B4X Rad. As @LucasMS said, you force all developper to use them. One big advantage is that we can develop for Java, iOS, android, arduino with B4X, with Java, no for now. What we just want is for developpers who need those features, they can stay with B4X. For new developpers form C#, Java, etc., they can port easily their projects.
Not true.
Yes, there is some exageration. I admit.
It doesn't work like this.
:)
 

Star-Dust

Expert
Licensed User
Longtime User
View attachment 94984


B4X:
Sub Process_Globals
    Type tAreaParam1(Base As Double, Altezza As Double)
    Type tAreaParam2(X1 As Double, Y1 As Double, _
                     X2 As Double, Y2 As Double, _
                     X3 As Double, Y3 As Double _
                    )
End Sub

Public Sub Area(Param As Object) As Double
    Dim Result As Double
 
    If Param Is tAreaParam1 Then
        Dim AreaParam1 As tAreaParam1 = Param
        Result = AreaParam1.Base * AreaParam1.Altezza * 0.5
    Else If Param Is tAreaParam2 Then
        Dim AreaParam2 As tAreaParam2 = Param
        Result = 0.5 * (AreaParam2.x1 * AreaParam2.y2 _
                      + AreaParam2.y1 * AreaParam2.x3 _
                      + AreaParam2.x2 * AreaParam2.y3 _
                      - AreaParam2.x3 * AreaParam2.y2 _
                      - AreaParam2.y3 * AreaParam2.x1 _
                      - AreaParam2.x2 * AreaParam2.y1)
    End If
 
    Return Result
End Sub
It is not polyformism, we are not listing a list of how to avoid using polymorphism. Polymorphism is much more.

In the 90s we used languages that did not have pointers and my teacher explains a trick to use arrays as if they were pointers. That trick didn't make that language more powerful and made pointers useless
 
Last edited:

Toky Olivier

Active Member
Licensed User
Longtime User
View attachment 94984


B4X:
Sub Process_Globals
    Type tAreaParam1(Base As Double, Altezza As Double)
    Type tAreaParam2(X1 As Double, Y1 As Double, _
                     X2 As Double, Y2 As Double, _
                     X3 As Double, Y3 As Double _
                    )
End Sub

Public Sub Area(Param As Object) As Double
    Dim Result As Double

    If Param Is tAreaParam1 Then
        Dim AreaParam1 As tAreaParam1 = Param
        Result = AreaParam1.Base * AreaParam1.Altezza * 0.5
    Else If Param Is tAreaParam2 Then
        Dim AreaParam2 As tAreaParam2 = Param
        Result = 0.5 * (AreaParam2.x1 * AreaParam2.y2 _
                      + AreaParam2.y1 * AreaParam2.x3 _
                      + AreaParam2.x2 * AreaParam2.y3 _
                      - AreaParam2.x3 * AreaParam2.y2 _
                      - AreaParam2.y3 * AreaParam2.x1 _
                      - AreaParam2.x2 * AreaParam2.y1)
    End If

    Return Result
End Sub

Please note the cleanliness, the legibility thanks to the indentations 😎😁
The thing is, we can ALWAYS find workarounds if we want. But sometimes, there is prices: code length, readability,... And we can understand... But new members, need to convice them...
 

LucaMs

Expert
Licensed User
Longtime User
Top