Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Properties, Methods, and Init questions...
Message
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Titre:
Properties, Methods, and Init questions...
Divers
Thread ID:
00830419
Message ID:
00830419
Vues:
52
Hey all,

I had a few questions concerning how to manage OO methodology:

PROPERTIES (with access/assign) vs. METHODS --

The programmer I replaced was VERY fond of properties and of using access/assign methods to do a lot of heavy lifting behind the scenes. At first I thought, "Cool!", but I am now thinking, "Ugh!" every time I have to work on that code.

Here is an example. We need to convert from file number fo file ID. Here would be the property-driven way of doing it:

- Have an object with two properties, FileNum and FileID.
- Set up assign methods on these two properties.
- In FileNum's assign method, calculate the FileID and store it to FileID.
- Get FileID by accessing the FileID property.

Alternatively, with methods/parameters:

- Have an object with two properties, FileNum and FileID (though you wouldn't really even need them), and method GetFileID(filenum AS parameter).
- Call the GetFileID(filenum) method of the object and get back FileID. Optionally, you could even store the FileID in the FileID property, though that seems like going a bit too far.

Over the years I have become a method man. I think they are more readable, more flexible, and more easy to change in complex systems. I guess I basically need to know where to draw the line when it comes to access/assign methods. Should they be used solely for data integrity and scrubbing purposes? How is everyone else using them? I fear I am missing something, as a lot of my objects just end up being glorified function libraries! On to the next question...

INIT vs. ASSIGNING PROPERTIES --

I am also a big fan of the Init method. I tend to pass a goodly amount of parameters to my object's Init and have the Init store the properites. Alternately, one could create the object, then assign properites, and then call subsequent methods.

Some Init parameters are obvious. If your object needs info just to get itself created, you have to pass it in. Should the rule be to just stop there? Any extra parameters should be assigned as properties? This kind of goes with the method question above, as there are times when I don't know whether to make a property or just have a data element be a parameter of a method. Any good rules of thumb to use for decisions like this?

I know a lot of this is OO theory, and gets learned with time (and I have already learned a lot). But our company is going to really start getting into more OO development soon, and sadly, I am probably the top OO guy here (scary, I know *smile*). We want to try to standardize on some design rules and concepts, so any ideas anyone has would be very much appreciated!

Thanks,
JoeK
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform