The final few weeks of class covered material on running time, particularly Big-Oh notation. Essentially, a program's running time can be bounded within O to prevent extraneous implications on the running time that are independent to the program running itself. For example, running a program on a brand new Acer laptop will certainly be faster than running that same program on a less advanced computer. The key thing for all programmers is to make sure the program runs at a fast rate such as lgn, which is the same thing as lg2n in computer science running time.
I can proudly say that I enjoyed the material that I learned in this course, but at the same time I can't ignore that I've also felt overwhelmed with some of the concepts near the end of the course. The hands-on interaction between fellow classmates and the TAs during labs was my primary source to fully understanding the material to the best of my ability. Of course with the unfortunate events of the strike, the labs were cancelled and a lot of material was self-learned. I feel unsatisfied that I couldn't learn to the best of my ability. Now that the strike is thankfully over, I hope I can possibly meet up with my TA in preparation for the final exam on April 28th. It is quite evident that the strike impacted not only the TAs negatively, but also the undergrad students and I'm sure myself, along with thousands of other undergrads are elated that the strike is over.
I loved going to Heap's lecture. Normally I didn't attend many of my classes this semester, but I always found a spot for this course and Psychology because they both thoroughly piqued my interest in learning. For the most part, I felt confident after leaving that lecture because the prof explained a lot of the concepts very clearly for the students to grasp.
I felt the two term tests were quite fair - I'm hoping the same for the exam. Plenty of time to review everything.
Assignments were also very fair, I just regret not putting as much effort as I did in A2 as I did for the A1 and A3. Oh well, hopefully they turn out alright!
The course syllabus was slightly changed so that the weightings of 6 quizzes reflected 10 quizzes. Strictly from a marks perspective, I'm okay with this because I did decent on the quizzes. However, I also understand the perspective of students who naturally started slowly on performing well on the quizzes. They weren't really given a shot to redeem their marks, so I find this change in the syllabus questionable.
I'm not sure what else to say... I'll sure miss writing here. :(
Thanks to all those who read my SLOGs and make sure to comment on any of my posts!
Taha Zulfiqar's CSC148 SLOGWinter 2015
Monday, 30 March 2015
Sunday, 29 March 2015
Week 11: Revisitng at an earlier SLOG
I can't believe this semester is almost over! It has definitely passed too quickly! In this week's SLOG, I'll look back at the very first post I made: Why Geeks Should Write.
Looking back at that week 1 SLOG, I couldn't agree more with the view I had in that post. My view hasn't changed, rather the experience I gained from writing my own SLOGs has further confirmed what I wrote that initial week. In addition, I would like to add a couple of points that was not addressed in my original post, but that I've now come to realize.
The main point I iterated in that SLOG post was keeping a log of events for reminds and potential debugging purposes. I mentioned that keeping track of what you've learned could save a lot of time, which it ended up doing when I wanted to re-visit concepts while studying for tests, which I specifically used my SLOG post on BSTs for Test 2. Writing what I learned in lecture, labs in my own words really aided in studying for the test. I plan to use my SLOGs as well as many others such as Arjun's SLOG, which I referred to when clearing up on OOP. Keeping track of what you've been learning along the way is quintessential to be successful in this course and while I thought it can be tedious at times, it is quite beneficial in the long-haul on your own personal knowledge of such a complex subject at times. I enjoyed looking at other SLOGs, mainly in reference to clear up a topic that I wasn't too confident in and I'm sure others have peaked over this SLOG as well. The point that wasn't addressed in my original post is the outright flexibility in terms of interaction with other classmates. I may not agree with some views on Kurt's SLOG, such as his implication that LinkedLists were easy to understand, but I also did find myself agreeing with his views on the use of recursion on LinkedLists. This is the most underrated aspect in my opinion as well because it's great to see the opinions of fellow classmates. It can only add to a heated debate in lectures, which makes the course that much more interesting!
Thus, it is very useful for geeks to continue writing.
Looking back at that week 1 SLOG, I couldn't agree more with the view I had in that post. My view hasn't changed, rather the experience I gained from writing my own SLOGs has further confirmed what I wrote that initial week. In addition, I would like to add a couple of points that was not addressed in my original post, but that I've now come to realize.
The main point I iterated in that SLOG post was keeping a log of events for reminds and potential debugging purposes. I mentioned that keeping track of what you've learned could save a lot of time, which it ended up doing when I wanted to re-visit concepts while studying for tests, which I specifically used my SLOG post on BSTs for Test 2. Writing what I learned in lecture, labs in my own words really aided in studying for the test. I plan to use my SLOGs as well as many others such as Arjun's SLOG, which I referred to when clearing up on OOP. Keeping track of what you've been learning along the way is quintessential to be successful in this course and while I thought it can be tedious at times, it is quite beneficial in the long-haul on your own personal knowledge of such a complex subject at times. I enjoyed looking at other SLOGs, mainly in reference to clear up a topic that I wasn't too confident in and I'm sure others have peaked over this SLOG as well. The point that wasn't addressed in my original post is the outright flexibility in terms of interaction with other classmates. I may not agree with some views on Kurt's SLOG, such as his implication that LinkedLists were easy to understand, but I also did find myself agreeing with his views on the use of recursion on LinkedLists. This is the most underrated aspect in my opinion as well because it's great to see the opinions of fellow classmates. It can only add to a heated debate in lectures, which makes the course that much more interesting!
Thus, it is very useful for geeks to continue writing.
Monday, 16 March 2015
Week 10: Impressions on Week 9
Hi everyone!
This past week was quite stressful - studying for Term Test 2 took a lot of time to make the sheet aid that I felt was suitable enough for the test.
The test itself wasn't too bad. Nothing to held my head up too high on, but I feel I understood what all three questions were asking and answered them to my best ability.
The first question involved questions about trees, specifically part A) asked what is the longest and smallest path in a 20 node tree. What I imagined was that a 20 node tree can have an arity (branching factor) of 1, thus the longest path can only be 2 nodes. Contrastingly, a 20 node tree could have an arity of 19, which can only lead a branching factor of 2. It felt quite awkward drawing the diagrams for these and it felt like something was flawed with my approach, but I had no idea in my mind and my aid sheet had nothing on smallest path either. Part b) of Q1 gave a tree and instructed us to organize in the post-order approach of a BST. I used my aid sheet definition and followed it up by vising the left child node, right child node and the main parent node itself.
The second question was implementing a BTNode tree, which was eerily similar to list_internal_between from the recent Lab, but it wanted even numbers from all the roots to be transported inside a list. Only a slight alteration was required on the final if statement for the code to include if the value % 2 ==0. This guaranteed only even numbers enter the list.
The 3rd and final question has me worried. I wasn't too confident with LinkedLists going into the test and I couldn't figure out a way to properly implement this function. I again referred to aid from my aid sheet and used my best judgement with comments to answer the question. Hopefully I get part marks for it!
In lecture, BSTs were covered more in-depth this time around, but nothing too different from what was already learned by doing the lab for that week.
This past week was quite stressful - studying for Term Test 2 took a lot of time to make the sheet aid that I felt was suitable enough for the test.
The test itself wasn't too bad. Nothing to held my head up too high on, but I feel I understood what all three questions were asking and answered them to my best ability.
The first question involved questions about trees, specifically part A) asked what is the longest and smallest path in a 20 node tree. What I imagined was that a 20 node tree can have an arity (branching factor) of 1, thus the longest path can only be 2 nodes. Contrastingly, a 20 node tree could have an arity of 19, which can only lead a branching factor of 2. It felt quite awkward drawing the diagrams for these and it felt like something was flawed with my approach, but I had no idea in my mind and my aid sheet had nothing on smallest path either. Part b) of Q1 gave a tree and instructed us to organize in the post-order approach of a BST. I used my aid sheet definition and followed it up by vising the left child node, right child node and the main parent node itself.
The second question was implementing a BTNode tree, which was eerily similar to list_internal_between from the recent Lab, but it wanted even numbers from all the roots to be transported inside a list. Only a slight alteration was required on the final if statement for the code to include if the value % 2 ==0. This guaranteed only even numbers enter the list.
The 3rd and final question has me worried. I wasn't too confident with LinkedLists going into the test and I couldn't figure out a way to properly implement this function. I again referred to aid from my aid sheet and used my best judgement with comments to answer the question. Hopefully I get part marks for it!
In lecture, BSTs were covered more in-depth this time around, but nothing too different from what was already learned by doing the lab for that week.
Thursday, 12 March 2015
Week 9: Impressions of Week 8
Hello everyone! The main topic covered in week 8 was on Linked Lists, but I will talk about my group's unsuccessful attempt to finishing assignment 2...
We felt were close, but unfortunately we couldn't figure out how to properly implement minimax, despite the hint given from Danny on Piazza. Our group understood exactly what needed to be done, but we simply couldn't think of the code to implement it. The method apply_move in TippyGameState took a lot of time to implement, but it really threw us off on how we could implement that within minimax to alternate the moves. Overall, a lot of time was used on TippyGameState, which left us very little time for minimax. We started the assignment a bit too late and that ultimately cost us with the improper and rushed completion of the assignment.
My group has learned our lesson from this and we must immediately start an assignment as soon as we can instead of being overwhelmed with it near the end. We will definitely keep this in mind with coding in the future - whether it's for a university assignment or if it's for a project from potential jobs down the line. It's great that I personally learned this early on and I will definitely make future accommodations to finish well before deadlines in case of bugs appearing in the code. Our group was gutted by our performance on this assignment, but we can't be too down on ourselves as there is also another assignment where we can redeem ourselves! The key is to remain optimistic and learn from your mistakes! I hope you (Reader) keep that in mind!
The main lesson I learned from this? Manage your time folks! There is nothing more important in university than time management!
Going to a less disheartening topic, before going to Monday's lecture, I read the recommended Think Like a Computer Scientist topic on Linked Lists.
I feel the name of the topic for them most part explains the concept - essentially linked lists has a node from a tree that refers to the next node in line as some form of a 'link' between the two. This pattern carries on until the next node is suddenly of 'NoneType', which means that we are finally at the end of the 'list'. Recursion is not necessarily required in Linked Lists, but it could still be used..
Here is a diagram from Think Like a Computer Scientist that illustrates this:
Essentially, 'cargo' refers to the current value of the node and 'next' links to the next node. Since there is no node after node3, 'next' is referring to None, which means our list has reached an end.
I immediately thought: why is this needed? When am I ever going to need this? So I went into Monday's class, specifically keeping these questions in mind.
Danny entrusted us with the idea of using diagrams to help with writing the code for Linked Lists. He gave us two options to draw the diagrams - 1) Make a diagram of a big list with a sublist within that big list, a sublist within the first sublist, and so on. 2) Make a diagram similar to the diagram from Think Like a Computer Scientist with each node referring to a next value.
Option 1 is useful on its own to get an idea of how the code would look like, but option 2 was much simpler to create, organize and potentially change and I much prefer this method. This is also the option Danny suggested to use.
Designing the class for LinkedLists seems fairly straightforward to the definition I provided:
Please do note that the default parameter of nxt=None, which means that if LLNode is implemented with only one parameter, it means that it's the only item in that successive list, meaning it's just a node.
A more suitable approach to give a bit more information about the linked list is using the LLNode as a wrapper:
The self.front instance variable refers to the front of the LinkedList, the self.back instance variable refers to the back of the Linked and self.size refers to the size of the list itself. This option naturally gives us more information about the specified LinkedList, which could make the code more efficient than using the previous LLNode class.
Here is a method, __contains__ we were asked to implement in lecture (This was a method for Class LinkedList.
The basic idea is to go from the front of LinkedList, through each node, until we get to the back of the LinkedList.
Danny told us to keep this procedure in mind when walking through lists. I felt his diagram really helped here:
You start off by referring the current node to the front of the LinkedList and you enter the while loop based on a specific condition. At the end of that while loop, you change the current node so it refers to the next node in the LinkedList. You can keep doing this until you reach self.back, which means you've hit the end of the list. Keeping this method in mind made it quite easy for me to follow along and understand how __contains__ was implemented.
This is the body for __contains__:
We start off by referring to the front of the LinkedList. The while loop condition continues iterating to the next node in the LinkedList until you either find the appropriate value, or until cur_node refers to NoneType, which means you've reached the end of the LinkedList. This skips through the while loop body and immediately returns False because the value is not within that LinkedList.
That's the gist of LinkedLists. I hope you gained some insight on the topic by reading my SLOG!
Wednesday, 4 March 2015
Week 8: Review on Week 7
Hello readers!
I can't believe it's been 2 weeks since Reading Week has passed! A lot of new material was covered in lecture, but my brain is still in vacation mode...
For this week, I'll be discussing the topics recently covered in lecture as well as my progression in Assignment 2.
A quick update on my progress in assignment 2, it's been tough for me and my partner to figure out minimax and rough_outcome. Aside from those, everything was doable, unfortunately minimax and rough_outcome make up nearly 50% of the grade. The methods for these are fairly unique and I have a general idea of what is supposed to happen - but I can't seem to find a way to properly implement it. Minimax essentially takes all possible gamestates in the game of Tippy and tries to make the best moves for the computer so that it never loses a game. I had a couple of questions in mind that I have asked and have received responses to - but they haven't really answered my questions - How to implement them. These include multiplying by -1, alternating moves and calling on methods such as apply_move from TippyGameState into minimax. Rough outcome takes all game states and decides a winner based on the available moves left. Once again, we knew the idea but unfortunately we can't implement it for now.
BT Nodes and Binary Search Trees (BSTs) were the topics covered in Week 7. It took me awhile to get the feel for implementing Trees, so it naturally took me a while to get used to the topics covered in Week 7 because they build upon Trees.
Essentially, BT Nodes are Trees that have 2 children that are named left and right as well as data that 'connects' those children together. The class is listed below with the __init__ method:

Note that the default parameters for left and right are of type None - this is a crucial concept for implementing the base case for methods in Class BTNode.
Also note that the body in __init__ is the same as the following:

An example of what I mean by 'connecting' these two children together can relate to ANY basic mathematical operators that can join 2 numbers together, which in this case is the left and right child.
We were given a handout for the method 'evaluate' in class BTNode and we were asked questions that could possibly lead us into implementing it.
Like with most recursion functions, we find a base case first and foremost.
If we look at the first example of the docstring, we note that there are no left or right children. At that point we don't need to evaluate anything, so we can simply just return b.data. This can be our base case.

Our generic case will be when there is an interior node with two children - specifically the two children that are each leaves with float data as specified by the docstring. Naturally, I found that it made sense to use the b.left, followed by the operator at b.data and then b.right to evaluate the expression.
The python built in function eval helps use use mathematical operations on strings and return a non-string value.

Using this we can form a statement to complete the generic case using recursion on the left child and the right child.

Note that going to the left tree followed by the node at b.data and then the right tree is of 'inorder' form to evaluate an expression of a tree.
There are also other ways to evaluate trees such as 'preorder' which evaluates the node itself at b.data followed by the left and right tree respectively. 'Postorder' evaluates the left tree, the right tree and the node itself. But 'inorder' serves our best interests at this time.
BSTs (Binary Search Trees) is a built upon the idea of the left and right children of BTs, but for BSTs, all nodes that are less than the current value are in the left subtree while all the nodes greater than the current value are in the right subtree. This leads to more efficiency. How you say? Suppose that we want a specific value of a tree and we know that specific value is less than the current value of the tree. With BSTs, we would only need to check the left subtree to find that value instead of going through every single node in the right tree as well.
I can't believe it's been 2 weeks since Reading Week has passed! A lot of new material was covered in lecture, but my brain is still in vacation mode...
For this week, I'll be discussing the topics recently covered in lecture as well as my progression in Assignment 2.
A quick update on my progress in assignment 2, it's been tough for me and my partner to figure out minimax and rough_outcome. Aside from those, everything was doable, unfortunately minimax and rough_outcome make up nearly 50% of the grade. The methods for these are fairly unique and I have a general idea of what is supposed to happen - but I can't seem to find a way to properly implement it. Minimax essentially takes all possible gamestates in the game of Tippy and tries to make the best moves for the computer so that it never loses a game. I had a couple of questions in mind that I have asked and have received responses to - but they haven't really answered my questions - How to implement them. These include multiplying by -1, alternating moves and calling on methods such as apply_move from TippyGameState into minimax. Rough outcome takes all game states and decides a winner based on the available moves left. Once again, we knew the idea but unfortunately we can't implement it for now.
BT Nodes and Binary Search Trees (BSTs) were the topics covered in Week 7. It took me awhile to get the feel for implementing Trees, so it naturally took me a while to get used to the topics covered in Week 7 because they build upon Trees.
Essentially, BT Nodes are Trees that have 2 children that are named left and right as well as data that 'connects' those children together. The class is listed below with the __init__ method:
Note that the default parameters for left and right are of type None - this is a crucial concept for implementing the base case for methods in Class BTNode.
Also note that the body in __init__ is the same as the following:
An example of what I mean by 'connecting' these two children together can relate to ANY basic mathematical operators that can join 2 numbers together, which in this case is the left and right child.
We were given a handout for the method 'evaluate' in class BTNode and we were asked questions that could possibly lead us into implementing it.
Like with most recursion functions, we find a base case first and foremost.
If we look at the first example of the docstring, we note that there are no left or right children. At that point we don't need to evaluate anything, so we can simply just return b.data. This can be our base case.
Our generic case will be when there is an interior node with two children - specifically the two children that are each leaves with float data as specified by the docstring. Naturally, I found that it made sense to use the b.left, followed by the operator at b.data and then b.right to evaluate the expression.
The python built in function eval helps use use mathematical operations on strings and return a non-string value.
Using this we can form a statement to complete the generic case using recursion on the left child and the right child.
Note that going to the left tree followed by the node at b.data and then the right tree is of 'inorder' form to evaluate an expression of a tree.
There are also other ways to evaluate trees such as 'preorder' which evaluates the node itself at b.data followed by the left and right tree respectively. 'Postorder' evaluates the left tree, the right tree and the node itself. But 'inorder' serves our best interests at this time.
BSTs (Binary Search Trees) is a built upon the idea of the left and right children of BTs, but for BSTs, all nodes that are less than the current value are in the left subtree while all the nodes greater than the current value are in the right subtree. This leads to more efficiency. How you say? Suppose that we want a specific value of a tree and we know that specific value is less than the current value of the tree. With BSTs, we would only need to check the left subtree to find that value instead of going through every single node in the right tree as well.
Wednesday, 25 February 2015
Week 7: Summary of Object Oriented Programming
Hi TA!
Please mark this for my week 7 evaluation!
The topic of inheritance wasn't too difficult to grasp for me. It is pretty straight forward and Danny made life easy on me in understanding it by starting off with simple examples.
This was an in-class example of two classes - Class A and Class B, where Class A had a method g(self, n), where it returned 'n' and another method in f(self, n), which returned the self.g(n). Note the 'self' is included in the parameter of those respective methods to ensure that the first parameter is in the instance of the Class A. Also note that the methods can be re-written as self.f(n) and self.g(n), which makes it a lot less complicated and confusing for me. This is because the first parameter is still an instance of that class.
Class B was a subclass of Class A, which means it inherited the characteristics(methods) of Class A. Class B also had a method self.g(n), but this one returned '2 * n'.
The result? The two print statements which called a.f(1) and b.f(1), printed 1 and 2 respectively.
a.f(1) is quite simple to understand - it directly calls self.f(1) from Class A, which returns self.g(n). self.g(1) simply returns n, which in this case is 1.
b.f(1) is a lot trickier. Despite Class B not directly containing self.f(n) as a method, it inherits self.f(n) from Class A, and then calls self.g(n) within its own class instead of Class A's g(self.n), thus printing 2 * 1, which is 2. In this case, Class B's self.g(n) is overriding Class A's self.g(n), only focusing on the method that is occurring in Class B
I found an intriguing way to remember the concept of inheritance:
I was sitting next to a buddy of mine and he explained to me to think of the subclass as the son who inherits the characteristics of a father and has his own techniques to surpass him. Needless to say, I'm a big fan of Naruto and in particular the father-son relationship between Naruto and Minato immediately popped to mind! Naruto(son) eventually learns the 'Rasengan' that his father mastered, but manages to surpass his father by learning the powers of the technique through his tailed beast powers. Similarly, Class B inherited Class A's methods, but managed to 'surpass' Class A's self.g(n) by return 2 * n instead of the n that was inherited.
OOP was also heavily reinforced in Assignment 1, where inheritance played a key role in the proper implementation of future games. There were three main classes - GameState (GS), ComputerStrategy (CompStrat) and GameView - the first two both were inherited by SubtractSquareGameState and SubtractSquareComputerStrategy respectively. Even though me and partner could've completed the assignment without either subclass, the profs emphasized the use of inheritance to help us design and implement future games for A2 and A3.
As such, we planned accordingly and used python's 'NotImplementedError' on various methods for the generic GameState and ComputerStrategy classes with a message stating that certain games were not implemented.
Me and partner designed the specific SubtractSquareGameState and SubtractSquareComputerStrategy so that the specific classes were subclasses to the generic ones. This meant that the methods with 'NotImplementedError' were also passed down, but we used the concept of overriding to complete our specific methods as requested from the assignment sheet. It was a fantastic learning experience.
Please mark this for my week 7 evaluation!
The topic of inheritance wasn't too difficult to grasp for me. It is pretty straight forward and Danny made life easy on me in understanding it by starting off with simple examples.
This was an in-class example of two classes - Class A and Class B, where Class A had a method g(self, n), where it returned 'n' and another method in f(self, n), which returned the self.g(n). Note the 'self' is included in the parameter of those respective methods to ensure that the first parameter is in the instance of the Class A. Also note that the methods can be re-written as self.f(n) and self.g(n), which makes it a lot less complicated and confusing for me. This is because the first parameter is still an instance of that class.
Class B was a subclass of Class A, which means it inherited the characteristics(methods) of Class A. Class B also had a method self.g(n), but this one returned '2 * n'.
The result? The two print statements which called a.f(1) and b.f(1), printed 1 and 2 respectively.
a.f(1) is quite simple to understand - it directly calls self.f(1) from Class A, which returns self.g(n). self.g(1) simply returns n, which in this case is 1.
b.f(1) is a lot trickier. Despite Class B not directly containing self.f(n) as a method, it inherits self.f(n) from Class A, and then calls self.g(n) within its own class instead of Class A's g(self.n), thus printing 2 * 1, which is 2. In this case, Class B's self.g(n) is overriding Class A's self.g(n), only focusing on the method that is occurring in Class B
I found an intriguing way to remember the concept of inheritance:
I was sitting next to a buddy of mine and he explained to me to think of the subclass as the son who inherits the characteristics of a father and has his own techniques to surpass him. Needless to say, I'm a big fan of Naruto and in particular the father-son relationship between Naruto and Minato immediately popped to mind! Naruto(son) eventually learns the 'Rasengan' that his father mastered, but manages to surpass his father by learning the powers of the technique through his tailed beast powers. Similarly, Class B inherited Class A's methods, but managed to 'surpass' Class A's self.g(n) by return 2 * n instead of the n that was inherited.
OOP was also heavily reinforced in Assignment 1, where inheritance played a key role in the proper implementation of future games. There were three main classes - GameState (GS), ComputerStrategy (CompStrat) and GameView - the first two both were inherited by SubtractSquareGameState and SubtractSquareComputerStrategy respectively. Even though me and partner could've completed the assignment without either subclass, the profs emphasized the use of inheritance to help us design and implement future games for A2 and A3.
As such, we planned accordingly and used python's 'NotImplementedError' on various methods for the generic GameState and ComputerStrategy classes with a message stating that certain games were not implemented.
Me and partner designed the specific SubtractSquareGameState and SubtractSquareComputerStrategy so that the specific classes were subclasses to the generic ones. This meant that the methods with 'NotImplementedError' were also passed down, but we used the concept of overriding to complete our specific methods as requested from the assignment sheet. It was a fantastic learning experience.
Thursday, 19 February 2015
Week 6: Object Orienting Programming (Mark for Week 7)
The topic of inheritance wasn't too difficult to grasp for me. It is pretty straight forward and Danny made life easy on me in understanding it by starting off with simple examples.
This was an in-class example of two classes - Class A and Class B, where Class A had a method g(self, n), where it returned 'n' and another method in f(self, n), which returned the self.g(n). Note the 'self' is included in the parameter of those respective methods to ensure that the first parameter is in the instance of the Class A. Also note that the methods can be re-written as self.f(n) and self.g(n), which makes it a lot less complicated and confusing for me. This is because the first parameter is still an instance of that class.
Class B was a subclass of Class A, which means it inherited the characteristics(methods) of Class A. Class B also had a method self.g(n), but this one returned '2 * n'.
The result? The two print statements which called a.f(1) and b.f(1), printed 1 and 2 respectively.
a.f(1) is quite simple to understand - it directly calls self.f(1) from Class A, which returns self.g(n). self.g(1) simply returns n, which in this case is 1.
b.f(1) is a lot trickier. Despite Class B not directly containing self.f(n) as a method, it inherits self.f(n) from Class A, and then calls self.g(n) within its own class instead of Class A's g(self.n), thus printing 2 * 1, which is 2. In this case, Class B's self.g(n) is overriding Class A's self.g(n), only focusing on the method that is occurring in Class B
I found an intriguing way to remember the concept of inheritance:
I was sitting next to a buddy of mine and he explained to me to think of the subclass as the son who inherits the characteristics of a father and has his own techniques to surpass him. Needless to say, I'm a big fan of Naruto and in particular the father-son relationship between Naruto and Minato immediately popped to mind! Naruto(son) eventually learns the 'Rasengan' that his father mastered, but manages to surpass his father by learning the powers of the technique through his tailed beast powers. Similarly, Class B inherited Class A's methods, but managed to 'surpass' Class A's self.g(n) by return 2 * n instead of the n that was inherited.
OOP was also heavily reinforced in Assignment 1, where inheritance played a key role in the proper implementation of future games. There were three main classes - GameState (GS), ComputerStrategy (CompStrat) and GameView - the first two both were inherited by SubtractSquareGameState and SubtractSquareComputerStrategy respectively. Even though me and partner could've completed the assignment without either subclass, the profs emphasized the use of inheritance to help us design and implement future games for A2 and A3.
As such, we planned accordingly and used python's 'NotImplementedError' on various methods for the generic GameState and ComputerStrategy classes with a message stating that certain games were not implemented.
Me and partner designed the specific SubtractSquareGameState and SubtractSquareComputerStrategy so that the specific classes were subclasses to the generic ones. This meant that the methods with 'NotImplementedError' were also passed down, but we used the concept of overriding to complete our specific methods as requested from the assignment sheet. It was a fantastic learning experience.
This was an in-class example of two classes - Class A and Class B, where Class A had a method g(self, n), where it returned 'n' and another method in f(self, n), which returned the self.g(n). Note the 'self' is included in the parameter of those respective methods to ensure that the first parameter is in the instance of the Class A. Also note that the methods can be re-written as self.f(n) and self.g(n), which makes it a lot less complicated and confusing for me. This is because the first parameter is still an instance of that class.
Class B was a subclass of Class A, which means it inherited the characteristics(methods) of Class A. Class B also had a method self.g(n), but this one returned '2 * n'.
The result? The two print statements which called a.f(1) and b.f(1), printed 1 and 2 respectively.
a.f(1) is quite simple to understand - it directly calls self.f(1) from Class A, which returns self.g(n). self.g(1) simply returns n, which in this case is 1.
b.f(1) is a lot trickier. Despite Class B not directly containing self.f(n) as a method, it inherits self.f(n) from Class A, and then calls self.g(n) within its own class instead of Class A's g(self.n), thus printing 2 * 1, which is 2. In this case, Class B's self.g(n) is overriding Class A's self.g(n), only focusing on the method that is occurring in Class B
I found an intriguing way to remember the concept of inheritance:
I was sitting next to a buddy of mine and he explained to me to think of the subclass as the son who inherits the characteristics of a father and has his own techniques to surpass him. Needless to say, I'm a big fan of Naruto and in particular the father-son relationship between Naruto and Minato immediately popped to mind! Naruto(son) eventually learns the 'Rasengan' that his father mastered, but manages to surpass his father by learning the powers of the technique through his tailed beast powers. Similarly, Class B inherited Class A's methods, but managed to 'surpass' Class A's self.g(n) by return 2 * n instead of the n that was inherited.
OOP was also heavily reinforced in Assignment 1, where inheritance played a key role in the proper implementation of future games. There were three main classes - GameState (GS), ComputerStrategy (CompStrat) and GameView - the first two both were inherited by SubtractSquareGameState and SubtractSquareComputerStrategy respectively. Even though me and partner could've completed the assignment without either subclass, the profs emphasized the use of inheritance to help us design and implement future games for A2 and A3.
As such, we planned accordingly and used python's 'NotImplementedError' on various methods for the generic GameState and ComputerStrategy classes with a message stating that certain games were not implemented.
Me and partner designed the specific SubtractSquareGameState and SubtractSquareComputerStrategy so that the specific classes were subclasses to the generic ones. This meant that the methods with 'NotImplementedError' were also passed down, but we used the concept of overriding to complete our specific methods as requested from the assignment sheet. It was a fantastic learning experience.
Subscribe to:
Posts (Atom)






