In our first series of programming articles, we introduced some basic concepts using examples in the C programming language. You learned about variables, operators, various data types and the different ways to use them, etc. These “components” appear in almost all conventional programming languages.
From our examples in C, you should have acquired a basic idea of what the structure of a C program looks like. In simple terms, you declare and define the variables you want to use (and make new data types in the form of structures, if necessary), and you manipulate those variables by writing parts of code. In programming, we refer to this as a “procedural paradigm” (paradigm – a fundamental style; a set of ideas, rules and patterns which determine the way a program is structured).
You may have also noticed some of the negatives of this way of programming – numerous functions, difficulty in determining the origin of an error, and inflexible code or being unable to represent or model your problem in detail using the given means. This does not suggest that C is a bad language or that the procedural paradigm isn’t a good one. What we are saying, however, is that this way of programming is unsuitable for some situations. That’s why our new series of articles will discuss a different paradigm called object-oriented programming (OOP).
The basic philosophy of OOP is based on the concept of objects – structures which contain data (called fields or attributes), and code in the form of procedures (here called methods, not functions). Objects can interact with each other, and an object’s method can modify the data contained within the object.
There are many subtypes of the OOP paradigm, but most commonly, object-oriented languages are “class-based” – meaning that an object is an instance of a class. All objects of a certain class have some similar features.
One of the key features of OOP is inheritance – when one class inherits another class, it keeps all the properties of the parent class but also adds new properties of its own. This is meant to “mimic” real life situations. For example, let’s say you have a class called Car and inherit a class called RacingCar from it. A racing car is still a car, just with some additional features. This enables a certain type of behavior in objects called polymorphism (which will be discussed later in greater detail).
Although object-oriented programming may seem overly complicated in the beginning, it is an amazing tool for modeling complex structures and solving problems; it enables modularization of code, making modifying the code or adding new features a simpler task, and makes the program more robust (resilient to errors). That’s why, in the following articles, we will more thoroughly explain the basic terminology – classes, objects, methods, inheritance, polymorphism, etc. Later, we’ll talk about some general principles and patterns for successfully building a robust, modularized and comprehensive object-oriented system.