Before we go into more detail about object orientation, let’s first look at the difference between procedural programming and object-oriented programming?
Procedurally oriented programming uses the “top-down” programming style. Problem is formulated as sequential string of subtasks to be done. Thus a free and thus unprotected data flow and a bad illustration of “real” conditions and relations prevail.
Object oriented programming
The object-oriented programming pursues the approach of the “bottom up” programming style. Problems are considered as a composition of a number of objects that interact with each other. This creates the advantage of reusability and encapsulation of data and associated functions.
Classes and Objects
The concept of object-oriented programming is primarily represented by classes and objects. It is important to distinguish classes from objects. Classes are the blueprint for objects and need to be defined. A class definition is comparable to a type definition.
Objects can later be created from the class, comparable to variables that are generated from a type.
- Description of a set of (almost) identical objects. The only difference is in the values of the attributes.
- Class describes the data and functions that characterize a set of objects.
- So class contains the prototype of an object.
- Each object adopts the attributes and behavior that are defined in its class.
- An object is a concrete element for a class that has been manufactured according to a specific construction plan.
- User view: The object provides a specific behavior
- Programmer’s view: Objects as parts of an application that work together to provide the desired functionality.
Attributes and methods
Attributes describe the data structure of the objects of a class, determine the state of an object. Methods are functions that an object can execute and that determine how an object should react when it receives a message. So attributes and methods are nothing else than variables and functions defined within a class.
Goals of object-oriented programming
Data abstraction through classes
Definition and use of application-specific data types and the operations possible on them in a class. This allows related data to be bundled into one data type. The access to the attributes does not take place thereby directly, but over the methods.
Agreeing on data and the functions that manage that data in an unit. Accesses can be restricted using modifiers. In general, the data elements of an object are completely encapsulated (private) and are not accessible to the user. not manipulable for the user. Only over public functions the user can access the object.
Reusability of program parts
The modeling of classes and objects and inheritance, when properly applied, provide code reduction on the one hand, and the formation of more abstract, reusable classes on the other.
Reliability and change friendliness
In the long term, the reuse of existing and already tested application components ensures greater reliability of the system. The modular structure facilitates the extension and modification of the application.
Through the principle of overloading operators, it is possible to use the operators known in one namespace of a data type (e.g. +,-,*,/,….) in another data type, but with a different meaning there.