04.08.2013 Views

Printing - FoxTalk - dFPUG-Portal

Printing - FoxTalk - dFPUG-Portal

Printing - FoxTalk - dFPUG-Portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

usiness rules because they aren't buried in either the front or the back end. If you coded all of<br />

your data validation rules in Visual FoxPro, then it would be difficult to reuse them in, say, a<br />

Visual Basic or Access application. If they were sitting in their own layer, then any front end<br />

could use them to send data to any back end.<br />

This is the general idea of two- and three-tier architectures. In practice, you have more flexibility<br />

in how you structure your applications if you're using Visual FoxPro to build a client/server<br />

architecture. In a two-tier architecture, you can enforce the rules entirely in the back end, entirely<br />

in Visual FoxPro, or in both places. For example, if a rule is that prices can't go up by more than<br />

20 percent, you can do this in SQL Server with a rule or constraint. You can do this in Visual<br />

FoxPro in the Valid event of a text box.<br />

This is a pretty simple rule to enforce. If you enforce it in Visual FoxPro, the user gets instant<br />

feedback and the back end doesn't have to spend time checking the price. If you have 100 users<br />

entering 200 orders a day each, this adds up to a lot of work the back end doesn't have to do. If<br />

the only front end accessing the back end data is your Visual FoxPro application, then you might<br />

wind up putting the bulk, maybe even all, of the data validation code into the front end.<br />

But what if other front ends need to access the data? If Access and Visual Basic applications can<br />

enter or edit orders, then you would want to validate price on the back end. As a wise person<br />

once said, "Write once, use many." If the only other applications to access the data were written<br />

in Visual FoxPro, you could write FoxPro code and share it, perhaps through a stored procedure<br />

or a data validation class.<br />

In a three-tier architecture, you can still split the work by enforcing data integrity in the front<br />

end. If the middle tier is the only one responsible for making sure that price increases are<br />

acceptable, then are you overly burdening that layer? What will you gain by either duplicating or<br />

moving the rule enforcement into Visual FoxPro on the front end?<br />

What is the middle layer written in? The Visual Basic team wants you to write the middle layer<br />

in Visual Basic, using VB 4.0's new ability to create OLE servers. The OLE server could be<br />

called from Visual FoxPro using OLE Automation. Data would be passed to the middle layer,<br />

which would validate it. If the data were rejected, the middle layer would let FoxPro know about<br />

it. If the data were good, it would be sent on to the back end and FoxPro would be told.<br />

You would use this VB middle layer from Visual FoxPro the same way you use any OLE<br />

Automation server. You might issue the following to start a conversation with the server:<br />

oData = CreateObject("VBServer.BizRules")<br />

When you wanted to send data to the middle layer, you might issue the following code:<br />

oData.Send("Update employee Set salary = 87000000")

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!