Introduction
Object oriented programming (OOP) is a programming concept that was invented to solve limitations of earlier programming paradigms. Therefore, it may be argued that OOP is a new approach to developing software. Whether OOP is an old or modern idea is open for debate. However, this paper focuses on the concepts that make up object oriented programming. It summarizes the relationship between structures, classes and unions, and OOP, and mentions the concepts of inheritance, objects, and polymorphism in OOP.
Objects and object oriented programing
In the programming world, things are often viewed into two perspectives – data and actions or operations on these data. This viewpoint is inherent in object oriented programing. However, in OOP and unlike in a procedural programming approach, data and actions on data are further organized into modular units. These modular units are what is often referred to as objects. To develop a complete program, a programmer has to connect these objects. Therefore, the basic aspect of OOP design involves objects and interactions of these objects.
An object in OOP can be described simply as a group of data and operations on these data. As Horton (2010, p.507) has highlighted, an object is a data structure. An object in OOP sense is more or less like a physical or real-world object. Keogh, Keogh, and Giannini, (2004, p.230 ) have mentioned that an object is characterized by both state and behaviour. This similarities of objects to real things makes OOP a very powerful programming approach (Keogh, Keogh and Giannini, 2004, p.123).
The term objects can also be very confusing to persons with little knowldge of object oriented programing. According to Oracle (1995), an object is a software bundle having similar state or data and behaviour. Classes, structures and unions are examples of objects in OOP. However, instances of a class have often been reffered to as objects (Keogh, Keogh, and Giannini, 2004, p.210), an aspect that can be a source of confusion.
Classes, structures and unions
An understanding of object oriented programing must include knowledge of classes, structures and unions. Classes, structures and unions are core concepts of object oriented programming. A class is simply a data type. It provides a blueprint from which to create specific objects. A class can describe real-world or abstract objects to solve specific problems. Horton (2010, p.508) has mentioned further that a class defines “the objects to which” a program relate. We can describe a class as an entity defining the features of a specific set of things that are identified by similar set of operations and parameters.
Structures and union are also custom data types. Barnett, O’Cull, and Cox, (2006, p.54) have described a structure as “a method of creating a single data object from one or more variables” or members that do not have to be of same data type. Classes, structures, and unions are often defined by a user depending on requirements of a program.
A union is more or less like a structure. Their format and purposes are the same. Actually, the declaration of a union is similar to that of a structure. The difference between the two is that unlike a structure, a union allows its members to share a common memory space. Members of a union begins at the same memory location such that a member is overwritten when another is updated. The ability of a union variable to store values is limited to only a single member at a time. To create real-life objects and store large amount of data, a structure is more valuable and prefferable than a union.
classes, unions and structures can all have data objects of different data types. This aspect is in contrast to arrays, which are usually characterized by elements of the same data type.
The difference between classes, and structures and unions is clear. In a class, the members are automatically set to private while in unions and structures they are set to public. Keogh, Keogh and Giannini (2004, p.243) have highlighted that a C++ complier often converts a structure (or rather a struct) into a class.
Inheritance
Inheritance is also a main feature of OOP. It is simply a feature that describes the link between types of objects. In C++, for instance, a class can inherit the behaviour and state of other classes. Therefore, because of inheritance a child class can be extracted from the parent class.
Polymorphism
Polymorphism is also an inherent aspect of OOP. It is a feature of object oriented programming languages that allows objects to be processed differently according to their class or data type. In other words, polymorphism make it possible to redefine derived classes’ methods. Horton (2010, p, 535) has pointed out that any true OOP language must be be characterised by polymorphism. The polymorphism feature of OOP languages makes it possible to manipulate values of varying data types through a similar interface.
This paper has exained the concepts of object oriented programming. It has summarized the relationships between structures, classes and unions, and object oriented programming as well as touched on the concepts of inheritance, objects, and polymorphism. These aspects of OOP makes it a very powerful programming approach.
References
Barnett, R.H., O’Cull, L., Cox, S. (2006). Embedded C programming and the Atmel AVR. Clifton park, New York: Cengage Learning.
Horton, I. (2010). Ivor Horton’s Beginning Visual C++ 2010. Indianapolis, Indiana: John Wiley and Sons.
Keogh,J., Keogh, J.E., & Giannini, M. (2004). OOP demystified.Emeryville, Califrnia: McGraw-Hill Professional.
Oracle. (1995). Lesson: Object-Oriented Programming Concepts. Web.