Object-oriented programming is, in my opinion, one of the most fundamental concepts to grasp in the field of computer programming. As starters, our only encounter with designing programs was by taking input, processing the data and output - all in one 'main' file. If we were to continue down this path, then large programs would become unnecessarily difficult, and rather disorganized, as the logic becomes more complicated. The question is: how does object-oriented programming play out in simplifying large projects?
First, we should take a look at object-oriented programming itself. At the core of object-oriented programming is the designing of classes - or rather, blueprints of objects. When we design a class, we should take into account what we are trying to emulate with this class, what data can we associate with it and what can such an implementation of this be used for. When we create an object in code, that is to say that we are merely declaring an instance of a class to be made. For example, we can have a class named Human that contains data about age, weight, name, height, and methods to emulate the person's speaking, walking, and interaction with other humans. When we create an instance of a Human, a Human object springs to life with its own set of data, and behaviors.
Another thing that can be used in object-oriented programming is the idea of inheritance. Say you have an Animal class, that has a method speak(). But what if you wanted that Animal to contain data specifically for one animal? Sure, you could reuse the same Animal code and rename it, but that would be tedious, no? This is where inheritance comes in; rather than do the above, you can have another class take in data and methods from another existing class, and modify/add to those features to make them specific for one group only.
Ultimately, how does object-oriented programming play out in designing needlessly large, complex programs? This is how I saw it. When I was a beginner in programming, I struggled with object-oriented programming and I told myself, "If I wanna design a large project I can just use the main interface and nothing else. Granted, while some early projects were successful (I made a Deal or No Deal game without the use of classes), the end result was confusing and all over the place.
However, I later encountered a Java beginner's book which helped me to realize that "object-oriented programming is much like designing the necessary components of a particular something (be it a car, slot machine or animal) and personalizing it with actions and values that pertain to it." It was rather helpful and it solidified my overall understanding of OOP as a whole, and I would never have any difficulty with the concepts again. Once I mastered object oriented programming, I decided to improve my Deal or No Deal game by representing each aspect of the game as its own object, and put those together to make a functional Deal or No Deal game. The end result: the code was more organized, more readable and professional than the previous cluster I had.
Thus, to answer my own question, object-oriented programming is useful for designing large projects because it allows you to create objects for each individual aspect of the program, and combine them together to create an organized, functional solution. Without object-oriented programming, sure, we can make large projects in one shot, but the result would be tedious and clustered / difficult to fix. Can you imagine trying to make a bank system without any objects? I wouldn't; in the end I wouldn't even be able to understand my own code, let alone others because the code would be all over the place.
No comments:
Post a Comment