[ENG VER] Know what is OOP? An Object-Oriented Programming Technique
Assalamu‘alaikum wr. wb.
Hello guys! Do you like coding? Or are you a programmer? Usually, if we want to do Coding, usually the things that are best known are Objects on Variables. Usually what we know among programmers is Object-Oriented Programming (OOP). Then, what is OOP? Let's discuss in this article.
Article Sources : Intelequia.com, Techtarget.com, and Glints.com
Object Oriented Programming (OOP) is a programming paradigm, that is, a programming model or style that provides guidelines on how to work with it and is based on the concept of classes and objects. This type of programming is used to structure a software program in simple and reusable pieces of code planes (classes) to create individual instances of objects.
Historically, different programming paradigms have emerged. On the one hand, sequential languages such as COBOL or procedural languages such as Basic or C focus more on logic than on data. On the other hand, more modern languages such as Java, C# and Python use paradigms to define programs, with OOP being the most popular.
With the OOP paradigm, the goal is to stop focusing on the pure logic of programs and start thinking about objects, which forms the basis of this paradigm. This helps a lot in large systems, because instead of thinking in functions, one thinks in the relations or interactions of the different elements of the system.
A programmer designs a software program by organizing pieces of information and related behaviors into a template called a class. Then, individual objects are created from the class template. The entire software program is executed by having various objects interact with each other to create a larger program.
A. Definition of OOP
Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior.
OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate them. This approach to programming is well-suited for programs that are large, complex and actively updated or maintained. This includes programs for manufacturing and design, as well as mobile applications; for example, OOP can be used for manufacturing system simulation software.
The organization of an object-oriented program also makes the method beneficial to collaborative development, where projects are divided into groups. Additional benefits of OOP include code reusability, scalability and efficiency.
The first step in OOP is to collect all of the objects a programmer wants to manipulate and identify how they relate to each other -- an exercise known as data modeling.
Examples of an object can range from physical entities, such as a human being who is described by properties like name and address, to small computer programs, such as widgets.
Once an object is known, it is labeled with a class of objects that defines the kind of data it contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method. Objects can communicate with well-defined interfaces called messages.
B. OOP Principles
In Object-Oriented Programming, there are four principles that form the basis for its use. The four OOP principles are as follows :
1. Encapsulation
Encapsulation presents all the important information of an object inside the object and only exposes the chosen information to the outside world.
This property ensures that the information of an object is hidden from the outside world by grouping in a class the characteristics or attributes that have private access, and the behaviors or methods that have public access.
The encapsulation of each object is responsible for both its information and its state. The only way in which this can be modified is through the object's own methods. In this way, the internal attributes of an object are inaccessible from the outside, and can only be modified by calling the corresponding functions. In this way, the state is kept safe from improper or unexpected uses.
To explain encapsulation we will use a car as an example. The car shares public information through the brake lights or turn signals to indicate turns (public interface). By contrast, the internal interface, the driving mechanism of the car, is hidden under the hood. When driving a car, it is necessary to indicate movements to other drivers, but not to expose private data about fuel type or engine temperature, as this is a lot of data, which would confuse other drivers.
2. Abstraction
Another principle of Object Oriented Programming is abstraction, which occurs when the user interacts only with selected attributes and methods of an object, using simplified high-level tools to access a complex object.
In OOP, programs are usually very large and objects communicate quite a bit with each other. Thus, abstraction facilitates the maintenance of a large code, where various changes may occur over time.
Thus, abstraction is based on using simple things to represent complexity. Objects and classes represent underlying code, hiding complex details from the user. Thus, it is an extension of encapsulation. Continuing with the previous example, you don't need to know all the details about how a car engine works in order to drive it.
3. Inheritance
Inheritance defines hierarchical relationships between classes, so that common attributes and methods can be reused. By defining basic attributes and behaviors in a class, secondary classes can be created, extending the functionality of the main class and adding extra attributes and behaviors. This is one of the keys to Object Oriented Programming.
Following the animal example, a single animal class can be used and an animal type attribute can be added that specifies the type of animal. Different types of animals will require different methods, for example, reptiles must be able to lay eggs and fish must be able to swim. Even if animals have a common method, such as moving, the implementation would require many "if" statements to ensure the ideal movement behavior. For example, frogs jump, while snakes slither. The inheritance principle solves this problem.
4. Polymorphism
Polymorphism lies in designing objects to share behaviors, which allows objects to be processed in different ways. It is the ability to present the same interface for different underlying ways or data types. By using inheritance, objects can override shared primary behaviors with specific secondary behaviors. Polymorphism allows the same method to execute different behaviors in two ways: method overriding and method overloading.
C. Advantages of OOP
1. Parallel Development
When working with a team, each programmer can build his own class.
By building a class separately, the components that have been formed can then be combined into a single unit.
This of course saves a lot of time compared to having to build classes one by one.
2. Reusable
With OOP, you can use various classes that you have created before.
This will certainly make it easier to use on other similar projects. You can also change the class according to your needs.
3. Scalability
OOP's various principles aim to simplify the needs of a wider or more complex program.
This makes it easier if there is a development from an existing program, adding some functions, objects, or other classes will be easier.
The program can also continue to function properly.
D. Disadvantages of OOP
1. Inefficient
Using OOP will consume more power on the CPU used. Therefore, it is highly recommended to use the latest tools when developing with OOP.
2. Requires strict Data Management
Another thing that developers complain about about OOP is the need for fairly tight control over the code.
This is because OOP will bring up some new codes if there are codes that are not working properly.
Of course this will add to the load on your device.
3. Possible Duplication
With the various conveniences provided by OOP, developing new programs from those that already exist will be easier.
However, this actually makes the various projects that are created feel like they are just duplicating.
To see this Article in Indonesian, can be see in here. And to read other Articles on Inzaghi's Blog on the History of Programming Languages, please see here.
Well, that's our brief explanation of Object Oriented Programming. Understanding OOP is one way to get your dream career in IT.
Thank You šššš :)
Wassalamu‘alaikum wr. wb.