How to oo this?

Posted by goo on 09-Jan-2018 06:12

def var oClassA as myClass no-undo.

def var oClassB as myClass no-undo.

def var oClassC as myClass no-undo.

:

:

def var oTmp as myClass no-undo.

if something then oTmp = oClassA else if somethingelse then oTmp = oClassC ......

run myStandardProcedure.

myStandardprocedure:

  if valid-class(oTmp) then do:

  use oTmp for all stuff related to the other classes....

end.

All Replies

Posted by Mike Fechner on 09-Jan-2018 06:16

Use an Interface that described the similarities between all those classes.

Von meinem iPad gesendet

Am 09.01.2018 um 13:13 schrieb goo <bounce-goo@community.progress.com>:

<ProgressEmailLogo-png_2D00_150x42x2-png> Update from Progress Community
<4TWJDR380VJY-jpg_2D00_70x70x2-jpg>
goo

def var oClassA as myClass no-undo.

def var oClassB as myClass no-undo.

def var oClassC as myClass no-undo.

:

:

def var oTmp as myClass no-undo.

if something then oTmp = oClassA else if somethingelse then oTmp = oClassC ......

run myStandardProcedure.

myStandardprocedure:

  if valid-class(oTmp) then do:

  use oTmp for all stuff related to the other classes....

end.

View online

 

You received this notification because you subscribed to the forum.  To stop receiving updates from only this thread, go here.

Flag this post as spam/abuse.

Posted by goo on 09-Jan-2018 06:21

Sorry, it seems that I can do oTmp = oClassB etc... I didn't thought that I could use a class as a variable pointer...

Posted by goo on 09-Jan-2018 06:38

All classes are similar, only some values that points to different stuff that is diff…
 
//Geir Otto
 

Posted by bronco on 09-Jan-2018 06:45

so why not pass the reference to the class as a parameter to myStandardProcedure instead of using oTmp? This seems like bad practise to me (no encapsulation)...

Posted by jmls on 09-Jan-2018 06:46

if the classes are the same (and it looks like they are) then you should new myclass with constructor data to populate the values rather than having 3 instances

def var oMyClass as myClass no-undo.

if something then oMyClass = new myClass(somethingdata) else if somethingelse then oMyClass = new myClass(somethingelsedata) etc 

run myStandardProcedure.

myStandardprocedure:

 if valid-class(oMyClass) then do:

 use oMyClass for stuff
end.

Posted by goo on 09-Jan-2018 07:28

The reason for me to instantiate them is because they are connection to some MSMQ queues. I don’t want to do this for each loop.
 
…make instances
… loop:
  Run myStandardProcedure(‘A’).
  Run myStandardProcedure(‘B’).
  Run myStandardProcedure(‘C’).
….endloop.
 
I know I should maybe have done this differently, but now I just  not want to change the stuff that works, just tune it a bit….
 
//Geir Otto
 

Posted by jmls on 09-Jan-2018 07:39

then pass A, B or C as a parameter to myStandardProcedure

…make instances

… loop:

 Run myStandardProcedure(oClassA).

 Run myStandardProcedure(oClassB).

 Run myStandardProcedure(oClassC).

….endloop.

myStandardprocedure:

 def input parameter pClass as myClass no-undo.

if valid-class(pClass) then do:

use pClass for stuff

end.

Posted by goo on 09-Jan-2018 09:58

I thought about that, but then I needed to have some logic extracted from the procedure. What is wrong with having a dummy class being a handle to the classes? Is it structural wrong? Slow?

Sendt fra min iPad

9. jan. 2018 kl. 14:41 skrev jmls <bounce-jmls@community.progress.com>:

Update from Progress Community
<4TQ25S8VIMK4-png_2D00_70x70x2-png>
jmls

then pass A, B or C as a parameter to myStandardProcedure

…make instances

… loop:

 Run myStandardProcedure(oClassA).

 Run myStandardProcedure(oClassB).

 Run myStandardProcedure(oClassC).

….endloop.

myStandardprocedure:

 def input parameter pClass as myClass no-undo.

if valid-class(pClass) then do:

use pClass for stuff

end.

View online

 

You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

Flag this post as spam/abuse.

Posted by Tim Kuehn on 09-Jan-2018 10:10

Class variables are just pointers to the class instance which means using it this way is how it's supposed to work.

IMO  the structural issue is that the various ClassA-C classes should be managed inside another class (E), and the "E" class exposes whichever one is appropriate for the work you want to do - generally by setting some kind of configuration state in the wrapper class which sets a property to that class. That'll wrap everything up nice and tidy and eliminate the need for the VALID-OBJECT() stuff in the called procedure. 



This thread is closed