Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Replace code in Form with Biz Method
Message
From
25/09/2019 04:19:12
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01671085
Message ID:
01671103
Views:
50
>Hi,
>
>I am working on refactoring the following code. Currently the code (pretty long, about 2000 lines) is executed in a method of a button click. And I am "moving" this code to a method of a Biz class.
>The form, on which the button reside, has text box controls that shows the progress. E.g. "Processing records number # ...", "Order Number: " + OrderNo. So, that the user knows that something is going one.
>The BIZ method code has to update the form controls (the progress above). Here is the segment of the current code that shows the progress:
>
>	thisform.wo_count.value = alltrim(str(nCountOrders))
>	thisform.wo_number.value = alltrim(str( CUR_PM_WOS.WO_NUMBER )	)		
>	thisform.equipment_id.Value = CUR_PM_WOS.EQUIP_ID
>	Thisform.Draw
>
>	DOEVENTS 
>
>
>How would you suggest to update the Form controls from the BIZ object code?
>
>TIA
>
>UPDATE. One idea I have is to pass the form reference to the BIZ method. But it seems to be a kludge.
>
>UPDATE 2. Another question is how to deal with a user interrupting the process. The form has Cancel button which set the form property lExit to .T. And the Process code checks for this value. Of course, when the Process code runs in a Biz method, the form property is out of scope. Unless, again, I pass the form reference to the BIZ method. But I am thinking/looking for a better solution/approach

If you want to achieve loose coupling, one approach could be to delegate the display of data away from the biz. The biz object is then only responsible to calculate the progress values, but not responsible for displaying the data in the UI. The command button and textboxes are not responsible for any of those and are disposable.

BINDEVENT(THISFORM.cmdButton,"Click", THISFORM.Biz,"DoProgressUpdate")
BINDEVENT(THISFORM.Biz,"OnProgressUpdate", THISFORM, "OnProgressUpdate")

In the Biz only set properties on its own class:

this.wo_count = alltrim(str(nCountOrders))
this.wo_number = alltrim(str( CUR_PM_WOS.WO_NUMBER ))
this.equipment_id = CUR_PM_WOS.EQUIP_ID
this.onProgressUpdate()

In the Form's method OnProgressUpdate():
AEVENTS(laEventSource, 0)
LOCAL loBiz AS Biz OF MyBiz.vcx
loBiz = laEventSource[1]

this.wo_count.Value = loBiz.wo_count
this.wo_number.Value = loBiz.wo_number
this.equipment_id.Value = loBiz.equipment_id

Now ideally you would like to relieve the form from the detailed task to update the Information. This can be achieved by creating a container object that contains the textboxes and other UI elements. On the container object you have then the OnProgressUpdate() method, and the form does not need to know the inner workings of the biz, neither of the progress info UI.

The only difference is that in the form you bind the biz to the container:
BINDEVENT(THISFORM.cmdButton,"Click", THISFORM.Biz,"DoProgressUpdate")
BINDEVENT(THISFORM.Biz,"OnProgressUpdate", THISFORM.cnt, "OnProgressUpdate")

In the cnt class OnProgressUpdate() is then the code that takes the calculated values from the biz and updates the objects accordingly.

The only responsibility of the form is to say, this is my Progress updater class, and this is my progress UI. What they do and how they do it, I don't care.
Christian Isberner
Software Consultant
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform