Wednesday, February 11, 2015

Week 6: Object Oriented Programming


There are many reasons that Object Oriented Programming important to programmers. It encourages abstract thinking and allows the programmer to isolate only the minimum information needed to solve a problem. Be as lazy as possible! Programming has many applications to real life situations because objects in the real world can be modelled as “objects” in code. When the problem size increases, it is sometimes useful to define objects with the information necessary allows us to manipulate them to get the information needed instead of inputting the same data constantly.

Anything can be made into an object by creating a class in Python. You can make a Class Ball, Employee, Company, Words, or even Sounds. Notice that not all of these are what we would define as an object in real life. The beauty of programming is the ability to be abstract, and create something out of nothing for lack of a better term.

An example of an object in Python can be a class called “Flower” which you can initialize with the type of flower and details about each flower like their name, average height, color, texture, etc. This will not create an actual flower, but the data that is entered can keep track of the information about Flower’s that you are interested in. It is essential to realize what data is important to keep track of and what isn’t. After initializing an instance of a Flower and calling a method, the first parameter (usually called self) lets the Flower instance gather all of the information it knows about itself so the method can use anything it needs. Once you create an instance of a specific flower, any data entered in parameters is stored in that instance for when you need it again.

No comments:

Post a Comment