I have some useful methods for physics calculations like acceleration / deceleration, speed, and some more.
Most of them require at least two measurements asunder in terms of time. So every time I want to use them, I have to implement a bunch of instance variables in my object that needs the calculation, for example for calculating an acceleration.
For example, wherever I need to calculate an acceleration, I include SLPhysics.h and write in my code:
double acceleration = [SLPhysics + calculateAccelerationForFirstMeasuredSpeed:v1 secondMeasuredSpeed:v2 firstMeasuredTime:t1 secondMeasuredTime:t2];
This works fine. But I would prefer a way that behaves like Core Animation, where most of the details for doing what has to be done is hidden from the user of the class.
So, in order to prevent me from making instance variables to remember the last measured values v1 and t1, I would prefer a simple-to-handle call like this:
double acceleration = [SLPhysics + calculateAccelerationForMeasuredSpeed:v measuredTime:t context:self];
Notice the context parameter. I think that's the way to go. But currently I have no big idea how those class methods can have access to a data structure, an NSMutableDictionary for example. If I would make instance variables, the class method would have no access. If I make it an instance method, the usage would be ugly and hard to read, and the user would be bothered by memory management and other stuff. Also all this allocation and initialization may cost too much (I think). I mean...look at Core Animation. That's so easy! I want the same thing for this. But they also had that problem, I guess. They have to remember some stuff. The animation duration, the context, etc.
I thought about writing values to a file, but that's too expensive. I could use SQLite. Too expensive operartions, probablys. These methods may be used in places that need 5 to 100 calculations per second. Arent there things like "class variables"?