Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proper Encapsulation Techniques?
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Proper Encapsulation Techniques?
Miscellaneous
Thread ID:
00131613
Message ID:
00131613
Views:
56
When using business objects accessing and modifying a bizobjs data from outside the bizobj is bad behavior for a properly encapsulated class. In order to maintain class integrity the developer has two options, each with its own drawbacks.

One option is to create a method for each field that needs to be replaced. For example, a developer might create a SetCustomerName() method which would replace the customer name field with a passed parameter. This is an excellent way of divorcing the data from the implimentation. The controlling object doesn't need to know from which table customername is being pulled or how it is formatted. However, this can become awkward if there are many fields that need to be replaced.

The other approach is to create a generic method that will accept a view, a field and a value, select that indicated table and replace the indicated field. For example, oCustomer.Replace('lv_customer', 'name', 'John Smith'). This allows the class to maintain some data integrity and a single method is all that is needed. However, with this implimentation object-oriented encapsualtion rules are violated. Specifically, the calling class needs to know details about the table and field the data is to be placed in.

To illustrate the two appraches:

LOCAL loCustomer

*-- Create the customer bizobj
loCustomer = CREATEOBJECT('bizCustomer')

*-- Bring in some data just for testing
loCustomer.Requery()

*-- Illustrate two different ways of replacing the
*-- customer name.
*--Example 1
loCustomer.SetCustomerName('Michael G. Emmons')

*-- Example 2
loCustomer.Replace('lv_customer', 'name', 'Michael G. Emmons')

loCustomer.Save()


I'd be curious to hear how other people deal with situations like this.

Michael G. Emmons
memmons@nc.rr.com
Next
Reply
Map
View

Click here to load this message in the networking platform