Tuesday, 21 January 2014

Week 3 Object-Oriented Programming

Object - Oriented Programming, different from most of the program we learned, is focusing on the creation of object which contain both data and functionality. We did an example in the first week, which is writing a class called Point. Class Point takes two numbers and treat them as a single object which represents the coordinate of a point. In the class, we use __init__ to initialized the Point, and then, if we want, we could add functions to it, too. For example, we wrote function to calculate the distance from the point to the origin. Note in the Object-Oriented format, when we call the function, we use:
>>>point.distance_from_origin()
instead of:
>>>Point.distance_from_origin(point)

No comments:

Post a Comment