Jan-12-2018, 07:33 PM
(Jan-12-2018, 07:13 PM)Gribouillis Wrote:(Jan-12-2018, 06:47 PM)mpd Wrote: Why? What benefit is gained by using classes here instead of methods?There are two immediate benefits:
- Classes is the tool that generally avoids struggling with global variables management. Using instances creates a new space where names can be defined and shared between different functions.
- I guess @mquesnel's project is to add new features to his/her games and it's going to be much easier if one uses classes from the beginning.
If you look at the code, you notice that I achieve the OP's objective to play the second game if the first one succeeds, and I do this by using an instance member, and no global statement. You can do the same with a value returned, as you suggested, but it is less extensible.
The OP doesn't have a "global variables management" problem. He/she is simply trying to get the success/fail status back to the caller. If the OP doesn't know about or understand return statements, are classes an appropriate topic to bring up?
Regarding extensibility... you can have simple, extensible examples without using classes. And if the OP is doing something simple with kids, it's probably better to not use classes at first anyway.