Saturday, February 14, 2015

My Summary Of Object Oriented Programming Concepts

So far in CSC148, we've been practicing object oriented programming (OOP) in Python, and although there's much more for us to learn regarding object oriented programming, I wanted to briefly summarize and explain some of the concepts we've learned so far in this field, and that's what today's blog is going to be all about. First of all, I'm going to give a brief introduction to object oriented programming and explain what exactly it means. Then I'll start explaining the concepts in OOP I've learned so far.

Ptting it in simple words, OOP (Object Oriented Programming) is a way of programming in which the user not only defines the data and its type, but also functions and methods that can be applied to it. This way of programming comes very handy especially when it  comes to abstract programming. For example, in our first week in CSC148, we made a class called Point where we create various methods and carry out various operations, based on an abstract set of co-ordinates given by the user.

Now, I will start explaining some concepts that I learned in object oriented programming.

1) Objects:

In OOP, we bundle up the data type and the methods applied to a data structure and call them objects, which are stored at a location in memory. In Python, every single thing from integers, strings to even classes, are objects. One of the advantages to this type of programming is the ability to import modules like math, str, unittest, etc., which make programming a lot more easier since instead of carrying out various operations on your own, you could already use pre-defined functions in a module.

2) Classes:


In simple terms, one can think of classes as a template or a backbone for creating objects, initializing variables and creating as well as implementing various methods. In out first week, in order to solve the abstract problem which I talked about in my explanation of object oriented programming, we created a class called Point where we initialized a variable name for the co-ordinates and started creating and carrying out functions like finding the co-ordinate's distance from the origin.

3) Inheritance:

I guess one of the cool things I've liked about Python so far is how you can create a new class that inherits objects and methods from the old class, thus making programming a lot more easier and elegant. This is what we call inheritance. In CSC148, we practiced inheritance by creating a class called employee which takes in details of an employee and returns their amount of pay and total pay. After that, we created subclasses called HourlyEmployee and SalariedEmployee which inherits methods from the employee class. This made the programming process, especially the process of initializing variables a  lot more easier since by inheriting the init function, one can avoid writing the same code over and over again which takes in a lot more time. This feature is especially important in cases where one has to create many different subclasses but carry out similar methods as in the parent class.

For further information regarding OOP, you can also refer to the link of one of my peers, which is https://humaircsc148slog.wordpress.com/2015/02/15/object-oriented-summary/.

And that's about what I've learned regarding object oriented programming that I can write off the top of my head. I know for sure that there's a lot more to learn regarding this way of programming and I look forward to it. Until then, keep coding and stay awesome.

No comments:

Post a Comment