Wednesday, January 22, 2014

Object-Oriented Programming

    "What is object-oriented programming?" one might ask themselves. Object-oriented programming is one of the few programming styles used by programmers worldwide, and in fact it is one of the most popular styles to date. The focus of object-oriented programming is to create objects to represent real life structures. This is accomplished through the use of classes that create an object that store all attributes about the object as the class's instance variables. From my experiences in CSC108, I spent most of the time writing programs in a procedural programming style. The difference between the two programming styles are immediately visible. Procedural programming paradigm focuses on creating separate functions that operate on the data passed through the parameters. However, object-oriented programming achieves two goals at once: storing the information about the object and using the functions defined in the class to provide the object the operations it requires. Because object-oriented programming is structured in an organized matter similar to data tables, it is easier to understand the concepts and idea of the code. Readability is valued highly by programmers and object-oriented programming achieve this through its organized structure.

    I will now discuss the format that object-oriented programming usually uses. Classes are self-defined by the programmer to represent the desired object. Each class uses a special method called __init__ to initialize attributes of the objects as instance variables. When does this happen? The __init__ method is called immediately when the constructor of the class is called which is the same name as the class with ( ) added to the end. This process is known as instantiation and finishes the storing information aspect of object oriented programming. The next step is to create methods in the class to manipulate the information stored in the instance variables and get the desired output. In object-oriented programming, think of it as that the object uses the method and not the method using the object as in procedural programming. It makes more sense for a dog to play than play to use the dog. This is the clarity that object-oriented programming provides for the coder and the reader.

    Object-oriented programming to me isn't a new concept as I programmed a tic-tac-toe game in Java with my class in 2013. Programming an interactive tic-tac-toe game that connected students to each other in the classroom isn't easy and with procedural programming paradigm, the code would have been all over the place. However, the use of classes with defined objects made each of the mini tasks that build the tic tac toe game much easier to code and organized the code into separate modules that can be accessed when required. Constructors, initializers, methods, and inheritance are some of the features that object-oriented programming provide for the coder and allow big projects to be built from smaller objects much easier. In my opinion, object-oriented programming is a very powerful style and will continue to be used by many coders in the future due to its flexibility, organization, and informative code.