Object-Oriented Programming, an Introduction
Category likeness to » . Added to Authentic Society 44 years ago.
Object-Oriented Programming is not a simple concept to grasp. Numerous OOP C++ books have been written about the subject. It implies many different software design techniques. In this article I briefly explain Object-Oriented programming in simple to understand terms.
Learning a computer language is much like learning a human language. Once you learn your second language, it becomes easier to learn additional languages. This is probably because while different languages sound different by ear, they are also linguistically very similar to one another. It is likely that by the time you are ready to learn a third language, the task is made much easier by your previous experience because you can quickly spot the important similarities between the two languages you already know. That knowledge can be only gained with experience. In the same way, when learning your first computer language, it is sometimes easy to ignore some of the important things. I believe that one of the things that is often ignored when learning a first computer language is the ability of thinking about a computer language as a set of features. Object-Oriented programming techniques are closely tied to software architecture and the abstract representation of what is called object. We use objects to design software, and therefore the act of programming by creating and manipulating objects is called Object-Oriented programming.
Every computer language has a set of features, sometimes referred to as language features. When a computer language is created it is not complete until it includes all of the features its meant to have, as specified in the design document for that language. For example, being able to add 1 + 1 is a language feature. This simple arithmetic is accomplished by using the plus sign (+) operator. The plus sign operator is a feature of the C++ programming language. Addition is one of the most commonly used operations in computer processing. Because of this, the plus sign operator is a feature of just about any programming language. It is easy to get carried away and think that things just work that way and 1 + 1 equals 2. We would like to avoid this kind of thinking when learning a computer language. Instead we will say that the plus operator is one of the features of C++.
One of the most significant features of the C++ programming language is the ability to create objects. In the following paragraphs we investigate the nature of objects and I will give you a brief overview of what these objects are.
Objects came into the world of computer programming for a reason. In the context of our discussion, it may be difficult to fully understand what an object is without greater experience with the C++ programming language, but it is too early to discouraged just yet! By doing some research, one can gather that the idea of an object isn't new in C++. In other words objects were not invented in C++ and they exist in many other computer languages as well. Objects have been previously introduced as a language feature in other computer languages. The origin of Object-Oriented programming can be tracked down back in time to languages such as Simula67 and Smalltalk. These are the first two languages to enable what is called Object-Oriented programming techniques. But where did the idea of an object come from exactly, and why? The roots of object-oriented programming can be traced back to 1960s. An american computer scientist, Alan Curtis Kay, along with some colleagues at PARC (and predecessors at the Norwegian Computing Center) has invented the term Object-Oriented programming.
The Object-Oriented (often abbriviated, OOP) concepts have been evolving over the past 40 years. But the main idea of what an object is remains relatively the same. It may be difficult to grasp the concept of an object because the notion of an object is an abstraction. It is a way of thinking about programming and problem-solving. C++ provides an interface for implementing that way of thought by giving you the class keyword. We use the class keyword in our code to indicate a class, which is a "blueprint" for the new objects that will be created based on it.
While an object exists in computer memory, like many other data types (such as int or a char), a programmer who works with object-oriented code doesn't always need to be aware of that fact (with the exception of few software designs), but rather, he or she will focus on how objects interact with one another. This is an important element of Object-Oriented programming because it allows us to focus on solving a particular problem. In addition, it can be said that an object is a user-defined type. If you have already started learning about data types in C++, or even C, you can say that an object is almost like an int or a char, but it is a custom type and it is defined by the programmer!
In contrast, we cannot create objects in the subset of C++, the C programming language. We could imitate object-oriented programming in C, and logically accomplish relatively the same things but C does not give us an explicit feature set to do that. So while it is not impossible, in C, it is difficult to adapt object-oriented programming techniques to your code. Therefore, you can see that Object-Oriented programming is really just a concept and C++ provides us with a set of features that allow us to easily build OO programs.
C++ offers features that allow us to focus on the software design and on how we think about solving engineering problems. C++ is an object-oriented programmer's best friend. It allows you to make design decisions and using objects is a big part of it. Am I hearing some of you saying, "But that doesn't exactly explain what an object is. Seriously, what is an object?" Well, we have only covered the theory. A deep understanding of objects in computer programming is always going to take time if you're learning about it the first time. Object-Oriented Programming is an extensive subject. But as you continue reading these tutorials, things will begin to make more sense.
Objects are initialized (or instantiated) classes. A class is a blueprint for the objects a programmer creates in his or her program. To give you a greater perspective, here is an example. Let's say you are writing a racing simulation that involves different types of cars. One of the challenges with this scenario is that you need to somehow represent different types of cars in your code. In programming langugaes that do not support or enable Object-Oriented programming, you could create different structures for different types of cars. But just because the cars are of different types, doesn't mean that they don't all have four wheels or one engine. By specifying these details in each separate structure, your source code repeats what you have already programmed! This makes the program larger in size, and in some cases slower to execute.
Now, imagine that you have clearly specified that a car has four wheels and one engine. Also, imagine that you only need to say this once in your source code. You would store this information in your car class. But what happens if you need two different cars, like in the previous example? In object-oriented programming, you can extend the original class by replicating all data it contains and only add those elements that are different. This object-oriented technique is called inheritance. In other words, we inherit class B from the original class A. We also extend class B to enable unique features. This allows us to create many different classes and save redundant code repetition. Moreover, by doing this, we are also focusing on the problem itself. This is by no means a tour-de-force of what is possible with inheritance in object-oriented programming. We will study it in depth in the following tutorials on this website.
Objects let you split your problem into different parts. These parts will work individually and in collaboration with each other, with the common goal of solving a complex problem. In C++, if you're trying to represent a car in your code, you may want to create a car object by instantiating that object from a class. Where a class is the data representation and an object instantiated from that class is the actual data that will be implemented in memory. We can create multiple objects that make up different parts of a car. For example, you can create the engine object and allow it to always be a part of the original car object. In object-oriented programming, this technique is refered to as object-composition. Inheritance and Object-Composition are frequently used features of the C++ programming language.
I had briefly mentioned classes for a reason. As you may have already guessed, in C++, when we think about creating objects, we first think about classes, that is the data representation of an actual object. Once again, a C++ class is a blueprint, it is an abstract representation of data. A class by itself is not an object, until it is initialized.
Authentic Society believes in free, original and pretty-decent quality content delivered via simple article format.
If you enjoy the quality of content on this page, have edit suggestions, improvements, questions, comments or business collaborations
feel welcome to reach me by email email@example.com - Thanks :-)
2006-2011 Articles and Tutorials Copyright Authentic Society.
Help us grow our community! We are also a social network: Join the new interest-based social network to meet people who share the same interests.