views:

71

answers:

1

I'm building a Flash project where it needs to handle some math, like an acceleration formula. My director has recommended a design pattern where I include the calculations directly in the flash object, but that doesn't seem like it's very good OOP.

What's the best practice for calculations in Flash? Should it be a separate object, so I can keep the "non-Flash" parts together and out of the way? What are people's experiences with including it inline vs. keeping it separate?

+2  A: 

On the contrary.

A flash object which accelerates should have its motion equations implemented in flash. It should have a class handling it, encapsulating the math. This way, it isn't stuck there, it is just in the right place.

If you take the math out of flash, you'll have to update the objects' positions by yourself, thus loosing a lot of flash's abilities.

M.A. Hanin
Encapsulation's a good idea. What do you think of a XML parser that processes the math?
VideoDnd
An XML parser to do all the math sounds like over-engineering to me, and introduces a pretty big weak point in your app. Just put your equations in a class and load that class up when you need to use it. If you want it to be dynamic without recompiling, hold config vars in xml (like, gravity, velocity, friction, etc) and just load those up and pass them to the equation.
Alex Jillard