Monday, 2 February 2015

inheritance in classes and recursion.

Learning about Inheritance in classes in python seems difficult, thats why i needed analogy of inheritance. 
Now i like to think about inheritance as versions of games. Take any console game for example, such as call of duty of GTA 5, and so on. There have been many versions of these games. For a game like GTA, think of all the versions, what do they have in common. Getting in the car, shooting, flying vehicles. all these can be put in  General  describes the game. 
Just like that we can describe the inheritance. All the general stuff that describes the game can be updated and modified to make the newer and better version of it. Therefore computer scientist make a general class for subclasses that inherits the data or methods from the general class.

Next thing to learn about was The recursion. 
recursion basically calling the same function inside itself, to make its job easier. This is used in merge sort. merge sort basically cuts down or divides a list of elements into smaller chunks until it has only one element, then it starts the sorting process. The dividing part is where the recursion comes into play. 
merge sort algorithm basically calls on itself to keep dividing the elements until there is only one element left. so that way its easier to sort.
once you understand the recursion and inheritance class design, that is where the journey starts!!

No comments:

Post a Comment