Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OOP and encapsulation
Message
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Title:
OOP and encapsulation
Miscellaneous
Thread ID:
00780932
Message ID:
00780932
Views:
43
In designing my application architecture, I've hit upon a couple of concerns; I'd like to solicit some second opinions, as well as ask a question.

First of all, the question:

Is it possible to enumerate through a class' properties, if one doesn't know in advance what they are? I need this because I'm doing some generic processing in a parent class, and won't know in advance what properties its subclass will have. I'd like to refrain from hard-coding specific subclass information, which of course would break encapsulation.

And speaking of encapsulation, it's actually the case that even if I'm able to enumerate these properties, I'm going to have to break it somewhere along the line.

I'll describe my structure a little bit:

This is the middle tier of my application -- the business objects. I have several collections, each based on a _Collection class. Each object in the collection is in turn based on an _Item class. The _Item class has some highly generic members, one of which is a Save() method. It's within the Save() method that I'd like to perform this enumeration I'm describing.

The goal is to build a SQL statement as I loop through the object's properties (this assumes for the present, of course, that my field names are the same as my property names), and then send that statement to the backend data class.

The reason I say it might not be possible to completely avoid breaking encapsulation is that I've got to steer an object to its corresponding data fields. For example, in order to build a SQL statement to update the proper record in the Address table, I've got to use the PersonID foreign key property of an Address object. Naturally those fields don't apply when processing a NewsItem object, so I'm forced to hard-code and thereby break encapsulation. My desire to enumerate the properties is to limit that hard-coding as much as possible; however encapsulation will still be broken (actually, this is more of a polymorphism issue than an encapsulation issue).

Do you see my problem?

This doesn't seem to be too advanced an OOP topic; I just haven't had occasion to run into the problem before now.

TIA for any ideas.

Read about the greatest fraud in the history of mankind.
See TaxableIncome.net.
Next
Reply
Map
View

Click here to load this message in the networking platform