Does anyone have any thoughts on passing full objects as variables as opposed to only pointers to the functions of the full object?
For example, I have a Dice object with two methods:
- RollDice(), randomizes the dice count
- GetCount(), retrieves the value
Now, I need to utilize the dice for more than just player moving, other objects need to be able to look at the Dice as well. Now, it seems wrong to me to pass the whole Dice object to these other objects, since then those objects would ‘technically’ be able to re-roll the Dice. Is it good or bad programming to pass only the GetCount function pointer to these other objects? Essentially saying “I’m not giving you the Dice, but I’ll show you how to read them.”.
Thoughts?
It seems that its an excellent oportunity to use the OBSERVER PATTERN (GoF);
Do you need any further explanation on pattern, or other classes implementations????