In the first few labs, we learnt to design classes, which was an extension of the material from CSC108. Then, we learnt about inheritance, ( a new topic for me), where a subclass is based on another, and we worked on desigining these subclasses. I think that the worksheets and labs we did were straightforward, where we only focused on designing one or two particular classes. It was easy to get the hang of these problems and perfect the class design.
The real tricky part came when it was time to do Assignment 1. This was the first time that I noticed the sheer difference in the transition from 108 to 148. Instead of being spoon fed and told what to do for each and every function, we had to do the hard thinking ourselves. I read through the assignment multiple times, and was still having trouble deciding where to begin. Designing separate classes is easy, but when it comes time to put all this information together and make a program which is supposed to play a game, it takes a lot more intuitive thinking. The information all made sense to me, but it is crucial to have a perfect understanding of all the classes and how they will be working together, before writing any code. This is one of the mistakes I made when I first started working on the assignment. I tried writing out code first. Then I realized I was making my generic Game State class specific for Subtract Square. I think for object oriented programming, you need to think on the broad scale, generic level, before working on any of the inherited classes. This works like a hierarchy. I made a flowchart for myself, which I think helped me out the most, and I will be doing this for future assignments. I thought about the main program and how the classes would interact (ie. how the game state and the strategy would be chosen), then i thought about the generic classes, then about the subtract square subclasses. Once it comes time to write the actual code, it was not as difficult, as long as you have a proper layout. This way you avoid running into any confusion, because you could always look back to the flowchart. I think the reason that we were told we must implement __init__, __repr__ and __str__ methods for all of our classes is that these our the most important things to think about when designing the class. If you have a good understanding of how the classes is initiated, and how it would be represented, then you can think about all the other methods or attributes of that class.
In conclusion, I was really happy with object oriented programming. After finishing up the game and playing subtract square a couple of times, I was happy to see how much I had learnt and how much progress I had made.
No comments:
Post a Comment