Information générale
Catégorie:
Programmation Orientée Object
Titre:
Where to put code for calculated properties?
Is there a "best practice" for where to put the code for calculated values stored in the properties of an object? Access methods are nice, but the calculations get executed a lot more often than necessary. In the interests of polymorphism, I thought about using a Calculate() method which is passed a code string (ie. oMyObject.Calculate("TAX")) to determine which calculation to perform. Although this provides a standard interface, I don't really think it meets the goals of polymorphism, since you have to know the code of each calculation you want to perform. Perhaps a custom method for each calculation is the best way to go (ie. oMyObject.CalcTax()). It does tell you exactly what the method does.
What do you think? Your opinion is appreciated.
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement