Object oriented programming is a fascinating concept. It opens the door to allow you to do many abstract things with python. I first realized this while working on the Subtract Square game for assignment 1. Object oriented programming focuses on using classes to make objects that are used to store data. For example in assignment 1, we made a class for GameState(GS). This was a general class that was used to keep track of a general game. It had different instance variables which are variables of the class to store information about the class. This general class stored information like whether or not it was the computers move, a list of available moves and whether or not the game is over. Now most of this information is useless without knowing information from a specific game since you wouldn't know when to update these variables.
So this is where the game specific classes come into play. We made a SubtractSquareGameState (SSGS) class. This class in conjunction with the general GS class completes the game. While initializing the SSGS class we inherited the GS class. So we automatically get the variables in the GS class. So we are able to update the variables from the GS class in the SSGS class because we now know specific information about the game. This assignment gave me a great understanding of how useful inheritance and Object Oriented Programming is. This entire game could have easily been done without the use of objects however doing it this way allows you to make multiple similar games since the groundwork for the game is already laid out in the general class. You would just need to program the specific code for the game you need to add. Where as if you were to do it without objects you would have lots of duplicate code.
No comments:
Post a Comment