Tuesday, January 21, 2014

Object-Oriented Programming

In our first weeks of class, we have learned about object oriented programming and its difference from traditional ways of programming that we were used to in 108. This was not a new material for me, since I already had experience with objects and classes, but I knew that I will have things to learn due to lack of practical experience with classes. Although, I had good intuition about classes and knowledge from some programming books that I've read. A good way of explanation of what is a class in those books was a microwave (it also explained importance of functions to make programs universal and allow users to chose their own cooking time and other parameters). Basically, every object can be classified (sometimes it's not that easy... For example, many people struggle to classify watermelon as a fruit or vegetable). Those objects will have some common properties shared among them, but not necessarily their values. In the example of microwaves, each microwave has the cooking part (the one that emits microwaves), but different microwaves have different power or even location of that part within the microwave. Also, some microwaves have additional properties, such as clock, while others may only have timer.
   Some classes can be inherited. For example, you may have a general class of vehicles, where every vehicle must have a steering wheel, but then, you get different kinds of vehicles, such as SUV or trucks, which also have a steering wheel, but differ in some other properties (number of wheels, ability to attach a trailer, etc. Every SUV is a car, but not every car is SUV. In python, every class is inherited from class "object" (similarly how everything in the world is made of atoms... or whatever is the smallest unit of matter). Object is everything (not money...).
   I also didn't mention methods. These are like... Things that objects do. For example, every car can drive, and the speed at which it drive depends on its properties (engine power/mass). Every truck can attach a trailer, but not every vehicle can (this method is unique to trucks). Methods work in similar way to properties, and they are just functions within methods, so I'll omit this explanation from this, already lenghty post.
    See how it goes next week with recursions, which should be very interesting, which should be very interesting, which should be very interesting, which should be very interesting, which should be very interesting, which should be very interesting, which should be very interesting...

No comments:

Post a Comment