I've been starting in with Class::MethodMaker and have some questions about get_set for an object.
Let's say I have an class that takes a few inputs, can be instructed to perform various computations, and produces various outputs. To be concrete, say the class is "sum", which takes two arguments, "a" and "b", and sums them to produce "c". (The real object has more inputs, does a much more complicated and expensive computation, and caches its result, but this toy example is good enough to illustrate my question.)
Using Class::MethodMaker, I declare a new_hash_init for the constructor, and "a", "b", "c" as get_set attributes.
After creating an instance (specifying "a" and "b"), I then tell the object to compute, which populates "c".
This approach feels wrong to me.... "c" should be read-only; the object should recalculate "c" whenever "a" or "b" is changed (so the internal state is consistent), etc.
If I were building the object by hand, I'd write set and get to ensure the object stays consistent. But MethodMaker offers only set_get as an accessor/mutator pair... To get the behavior I want, I'd need to override the methodmaker canned procedures, so much so it doesn't seem to make sense to use it.
- Should I be using a different design?
- Should I not be using Class::MethodMaker?
- What is the best design for a situation like this? Don't most objects need to adjust their internal state when a set is used to change one of their attributes?
Thanks for any advice ---
sigma