Sunday, February 15, 2015

week 6 object oriented programming

  Python is a powerful language that we can program toward objects. We have used objects since we started using python, such as list, dictionary, string. They all have built-in methods that were properly loaded inside the object and we can use them intuitively, for example, when we want to find the first item in a list l, we use l[0]. Also, we can print a list [1, 2, 3] and we can get [1, 2, 3] as we desired to see.
  Moreover, we can build our own class. It is fairly intuitive because what we deal with all day could be abstracted into a class. For example, the roster, registry system, cashier system and even games! There are lot of built-in method we can use to make our own class be used in a way we used for other basic objects such as list, string. They are __str__, __repr__, __contains__, __eq__, etc.
 We can also define our own methods to fit the class we are about to write. For point class, it can have method to calculate the distance from the origin. For roster, it can have method to report the people by some information we are interested in. For games, we can have methods to keep track of the process of this game and return some useful information or execute the move to lead us to the next state. It's all open ended.

No comments:

Post a Comment