Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
OO Design Question and recursion question?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00266441
Message ID:
00267385
Vues:
26
>
>
define class Part as custom
>procedure CalculateCost()
>* abstract method
>endproc
>enddefine
>
>define class SimplePart as Part
>procedure CalculateCost()
>return this.nCost
>enddefine
>
>define class CompositePart as Part
>procedure CalculateCost()
>local lnCost
>lnCost = 0
>for each oPart in this.oCollection
>   lnCost = lnCost + oPart.CalculateCost()
>endfor
>return lnCost + this.nCost && in case the composite has a cost to add
>                           && to the whole
>enddefine
>
>
Yes, this is something similar to what I had in mind. It would be difficult to find an instance of needing to go to 127 levels deep. I was originally thinking of having a seperate class to store the collection in, but I may not need to do that. That would reduce the number of method calls in half.
To not do recursion would require me to keep track of levels and start at the outmost level and work in. That would be VERY slow compared to recursion since I would have to loop thru a collection of all the objects once for every level. That would also require the objects to know who there parent was in the bom, whereas I only want the parent to be aware of who there children are since a part could be in multiple boms.
Derek Agar
Acctware Business Systems
derekagar@acctware.com
ICQ: 42332100

***********************
When in trouble call 911

He that dwelleth in the secret place
of the most High shall abide under
the shadow of the Almighty.
Psalm 91:1
***********************
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform