Replace conditional statement with Polymorphism

Martin Obongita martin.obongita at yahoo.com
Sat Jul 2 20:54:09 UTC 2022


 Thanks Phil,
Your code looks well thought out and smart.I'll try it.
Rgds,Martin.    On Saturday, July 2, 2022 at 09:06:24 PM GMT+3, Philip Tulett <philip.tulett at pdq-networks.com> wrote:  
 
 
Hi Martin,
Corrected!
That looks like:-Calculate lPixels as int(lColLength/5)If mod(lColLength,5)   Calculate lPixels as lPixels+1End If
Kind regards Phi

-------- Original message --------From: Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> Date: 02/07/2022 18:49 (GMT+00:00) To: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com>, Rob Mostyn <mostyn at platformis.net> Cc: Martin Obongita <martin.obongita at yahoo.com> Subject: Re: Replace conditional statement with Polymorphism 
 Hi Rob,
I have a report class in which I want to display columns.
The length of the columns should depend on the longest data in that column.I get the data and approximate its length in pixels.


Calculate lColLength as pColLength

If lColLength<=5

Calculate lPixels as 1

Else If lColLength<=10

Calculate lPixels as 2

Else If lColLength<=15

Calculate lPixels as 3

Else If lColLength<=20

Calculate lPixels as 4

Else If lColLength<=25

Calculate lPixels as 5

Else If lColLength<=30

Calculate lPixels as 6

Else If lColLength<=35

Calculate lPixels as 7

Else If lColLength<=40

Calculate lPixels as 8

Else If lColLength<=45

Calculate lPixels as 9

Else If lColLength<=50

Calculate lPixels as 10

Else If lColLength<=55

Calculate lPixels as 11

Else If lColLength<=60

Calculate lPixels as 12

Else If lColLength<=65

Calculate lPixels as 13

Else If lColLength<=70

Calculate lPixels as 14

Else If lColLength<=75

Calculate lPixels as 15

Else If lColLength<=80

Calculate lPixels as 16

Else If lColLength<=85

Calculate lPixels as 17

Else If lColLength<=90

Calculate lPixels as 18

Else If lColLength<=95

Calculate lPixels as 19

Else If lColLength<=100

Calculate lPixels as 20

End If


Quit method lPixels


You are right that this is old Omnis classic mindset.If there is a way to replace the IF statement in my code, it will do me a great deal of good.
Rgds,Martin.





    On Saturday, July 2, 2022 at 08:32:47 PM GMT+3, Rob Mostyn <mostyn at platformis.net> wrote:  
 
 H Martin,
object oriented programming requires a complete mind shift from procedural (Omnis Classic) programming.   More than that, it is a multidimensional or rather multi layered mind shift.  This transition took me about 18 months to get some 20 years ago.  I am sure you are somewhere along the curve yourself but I/we cannot tell how far. 
My suggestion is that you focus on a class / subclass hierarchy to address, or at least partially address your challenge.  The solution will most likely be a combination of the two methods.
Are your conditional statements implementing change in behaviour, change in business logic, change in presentation or change on … whatever?  
To answer your question properly requires a good understanding of your code base which you have and we don’t, so Its difficult to answer your questions succinctly.
Other may chip in with a more academic response.
Cheers,Rob


On 1 Jul 2022, at 20:45, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
Hi Listers,
I have an academic question about object-oriented programming.How is "polymorphism" implemented in Omnis Studio?
I have many conditional statements in my code: if...else if, switch...case that keeps breaking whenever I make a change in a related method elsewhere.Is there a sample library in the HUB which best described how to work with code that can take many forms?
Kind regards,Martin O.

_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com
Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 


  
_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com
Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 
  


More information about the omnisdev-en mailing list