Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Business object and OOP
Message
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00832637
Message ID:
00832772
Views:
16
Hi!

Your question reveals an excellent understanding of the problem!

The basic problem is this: no business object framework for VFP (that I know of) supports the polymorphic query, which is what you are trying to do. You want to query the table for parent item records and have it return to you instances of the subclasses.

There are two things you can do:
Option 1. As you mentioned, you can create another utility (helper) class that returns a collection of items that contains instances of the correct subclass. For example, it would retrieve all the items you are interested in, then it would look at the item type and translate M into MatrixItem, A into AssortedPackItem and so on. This would be the most object-oriented way to go, but I cannot recommend it because the infrastructure just isn't there to support it. Databinding and database updating of this collection would be too big of a hassle. You could put this method on the parent container class (Invoice, I think, in your example) but even this design is not clean because you are causing the container class to have way too much knowledge about the contained class.

Option 2. Forget about subclassing. Just create one instance of an Item class that handles all the items for the collection. Forget about polymorphism. Just use IF and CASE statements and run different behavior based on the type field. This is not object-oriented but its the way people do it if they don't have the polymorphic query.

The real way to handle the situation in an object-oriented fashion is to use a persistence layer which is a factory for your business objects and knows about the inheritance relationships between your domain classes. I have an article on the polymorphic query in the next issue of UT magazine that shows how it can be used in .NET.

Updated: There is one more way that I almost forgot about. Separate the unique behavior of the subclasses out of the business object hierarchy and put that into a hierarchy of strategy classes. Steven Black has an excellent article about this at http://www.pinnaclepublishing.com/FT/FTmag.nsf/0/17789DA0C3D4F0C6852568E8007AC8FF. This is the way I had to do it in VFP without the polymorphic query. Using a persistence layer with Object/Relational mapping is still be best way, but the strategy pattern also works.



>Hi,
>I am newbie of BO and OOP. Recently, I try to apply BO & OOP in my development - Inventory Control.
>
>In my application design, it supports multiple types of product - normal, matrix, assorted pack and repacking. There are quite similar with each other, of course, some differences such as the way of update stock qty, extra fields that required for certain item type.
>
>I am thinking to have a general class, and create subclasses on it to perform specific task which is most common way as I know. It may works fine here.
>
>However, in my POS/Invoice module, program will not know the item type key-in/scanned at least search from database. Since, I have multiple of Item class (each for each type of item), how to know which class should be initiated for SKU/Barcode lookup? Should I create one more class just for lookup, then create a appropriate object??
>
>Any comments?
>Please advise.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform