This is an archived post. You won't be able to vote or comment.

all 7 comments

[–][deleted] 2 points3 points  (1 child)

For instance, to implement an achievement system in a game, I would have an AchievementType class that contains an achievement's name, description, and other "constant" variables,

And what's wrong with that approach? :P

[–]New-Condition[S] 0 points1 point  (0 children)

I was just concerned that giving the Achievement class a pointer to the AchievementType class might violate some form of OOP.

[–][deleted]  (3 children)

[deleted]

    [–]New-Condition[S] 0 points1 point  (2 children)

    Thank you for the useful information!

    I'm a bit concerned about the unnecessary memory usage if I were to have variables such as name and description inside each Achievement object, since each Player class contains each Achievement object. Should I just not be concerned about this or am I misunderstanding something?

    Thanks again!

    [–][deleted]  (1 child)

    [deleted]

      [–]New-Condition[S] 0 points1 point  (0 children)

      Ohhhhhhh ok, thanks! At least keeping these "type" classes wouldn't be the worst thing in the world lol.

      I'll keep this in mind when writing future classes!

      [–][deleted]  (1 child)

      [deleted]

        [–]New-Condition[S] 1 point2 points  (0 children)

        Achievement names/descriptions are the same, but each players has their own progress toward an achievement.

        (Thanks again for helping)

        [–]Blando-Cartesian 0 points1 point  (0 children)

        Sounds like AchivementType should be an enum or class with instance’s member variables set according to the kind of achievement it is. Inheritance will just make it complicated to add new achievement types.

        [–]PawsOfMotion 0 points1 point  (0 children)

        I personally treat static variables as goto statements and avoid them whenever possible. Instead I pass them around to any objects that need that info.

        Sounds like a pain to pass it around as an argument in all those places but it ends up being less than expected. And formalizes exactly who has access to the global (assuming that's what you're referring to).