This article was automatically translated from the original Turkish version.
Object-oriented programming is the technology of the 1990s and today, and it is likely to continue as the dominant programming technology in the future. It has completely replaced Structured Programming from the 1970s.
In object-oriented programming, every element in the programming environment is treated as an object, and the properties of these objects can be modified to give them new forms. Additionally, each object has associated events to which it responds. Each object has been designed with different methods that can be applied to it.
While Structured Programming emphasizes programming commands, Object-Oriented Programming requires the programmer to have detailed knowledge of the objects in the environment, their properties, the events they respond to, and the methods applicable to them.
Object-Oriented Programming (OOP) is a programming language model that focuses on objects and operations performed on them, rather than logical operations. In OOP, programs are designed by enabling objects to interact with each other. Java, C++, C#, Python, PHP, JavaScript, Ruby, Perl, Smalltalk, and Objective-C are the main object-oriented programming languages. OOP theory mandates the implementation of four fundamental features; if even one is missing, the language is not considered OOP.
These four fundamental features are:
Abstraction in OOP refers to the ability of the programming language to process different types of data and classes in distinct ways. Fundamentally, it is the capability to redefine methods and derived classes.
For example, everything on Earth is an object. In computer software, an object is a representation of an entity. A building is also an object. To represent a building in software, we must identify its distinguishing properties. Characteristics such as building height, exterior color, number of floors, floor area, and floor dimensions are the most obvious features for representing a building. Therefore, in the computer representation of the object, properties play a central role.
The characteristic properties of an object and the actions it can perform are called methods. In this sense, the result of abstraction is that an object can be represented by its properties and methods.
OOP languages implement abstraction through the class structure. Within a class, the properties and methods belonging to that object are defined. However, a class is a structure and cannot be used directly. Instances created from the class inherit all its properties and methods and can be used directly within the program.
In abstraction, when a superclass is desired that carries the properties and functions of subclasses but has no instance of its own, an abstract superclass is created. The methods of an abstract class can be defined as templates to be overridden by subclasses or as abstract methods. A class with an abstract method automatically becomes abstract itself, and no objects can be instantiated from abstract classes.
Below is an example of abstraction. An abstract class named "Sekil" has been created. A subclass named "Dikdortgen" has been derived from this class. A method named "cevre" has been added to this subclass. Since this method is common to other subclasses of "Sekil", it has also been included in the abstract "Sekil" class.
Encapsulation is one of the fundamental concepts of OOP. It defines the boundaries for what parts of classes and methods can be viewed or modified by users. Three access modifiers can be mentioned: public (open to all), private (private), and protected (protected).
Public members are visible and modifiable by everyone, making them the least secure type of class member. It is not recommended to make methods that alter the internal structure of a program public. The public modifier is used for data that is intended to be added or modified by external users.
The protected modifier is a more secure access modifier than public. It can be viewed or accessed within the same class. Additionally, it can be viewed or accessed by the parent class, classes derived from it, and classes within the same package.
Private is the most secure access modifier. Private members can only be viewed or accessed by the class in which they are defined. Classes can be private, and so can their properties and the data they hold.
Below are three properties of an object: private, public, and protected. A student’s name, department, and GPA can be viewed by external users, while the ID number can only be viewed and modified within the "Ogrenci" class. The department ranking can be viewed and modified within the "Ogrenci" class or within classes derived from it.
Polymorphism is the ability of an OOP language to process different types of data and classes in distinct ways. More specifically, it is the capability to redefine methods and derived classes.
Below is a screenshot that illustrates polymorphism more clearly. Two subclasses, "Kare" and "Ucgen", have been created under the superclass "NesneCiz". The "Ciz" method is used to correctly draw two different geometric shapes.
Inheritance is a mechanism that establishes a parent-child relationship between classes and allows common methods and properties to be shared across them. It is one of the fundamental concepts of OOP. It enables the construction of new classes on top of existing ones. There are five types of inheritance.
Below, a subclass named "FizikOgrenci" has been created from the "Ogrenci" class. The "FizikOgrenci" subclass is a more specific object group that can use the methods of the "Ogrenci" class.
No Discussion Added Yet
Start discussion for "Object-Oriented Programming" article
Abstraction
Encapsulation
Polymorphism
Inheritance