Object-oriented programming

Object Oriented Programming (OOP). It is a paradigm of programming that uses objects and their interactions to design applications and computer programs . It is based on various techniques, including inheritance , abstraction , polymorphism, and encapsulation . Its use became popular in the early 1990s . Currently, there are a variety of programming languages ​​that support object orientation.

Summary

[ hide ]

  • Introduction
    • 1 The state
    • 2 The behavior
    • 3 The identity
  • 2 Origin
  • 3 Fundamental concepts
    • 1 Class
    • 2 Inheritance
    • 3 Object
    • 4 Method
    • 5 Event
    • 6 Message
    • 7 Property or attribute
    • 8 Internal state
    • 9 Components of an object
    • 10 Identification of an object
  • 4 Characteristics of OOP
    • 1 Abstraction
    • 2 Encapsulation
    • 3 Principle of concealment
    • 4 Polymorphism
    • 5 Inheritance
    • 6 Garbage collection
  • 5 Among object-oriented languages, the following stand out
  • 6 See also
  • 7 Sources

Introduction

Objects are entities that combine state ( attribute ), behavior ( method ), and identity :

The state

It is composed of data , it will be one or more attributes to which specific values ​​(data) will have been assigned.

Behavior

It is defined by the procedures or methods with which said object can operate, that is, what operations can be performed with it.

The identity

It is a property of an object that differentiates it from the rest, in other words, it is its identifier (a concept analogous to the identifier of a variable or a constant).

An object contains all the information that allows it to be defined and identified against other objects belonging to other classes and even against objects of the same class, since it can have well differentiated values ​​in its attributes. In turn, objects have interaction mechanisms called methods, which promote communication between them. This communication in turn favors the change of state in the objects themselves. This characteristic leads them to be treated as indivisible units, in which state and behavior are not separated.

Methods (behavior) and attributes (state) are closely related by the set property. This property highlights that a class requires methods to be able to deal with the attributes it has. The programmer must think indistinctly about both concepts, without separating or giving greater importance to any of them. Doing so could lead to the wrong habit of creating information-containing classes on the one hand and classes with methods that handle the former on the other. In this way, a structured programming camouflaged in an object- oriented programming language would be carried out .

OOP differs from traditional structured programming, in which data and procedures are separate and unrelated, since the only thing that is sought is the processing of some input data to obtain other output. Structured programming encourages the programmer to think primarily in terms of procedures or functions, and secondly in the data structures that those procedures handle. Only functions that process data are written in structured programming. OOP programmers, on the other hand, first define objects and then send them messages asking them to perform their methods themselves.

Origin

The concepts of object-oriented programming originate from Simula 67, a language designed for simulation, created by Ole-Johan Dahl and Kristen Nygaard of the Norwegian Computing Center in Oslo. At this center, they worked on ship simulations, which were confused by the combinatorial explosion of how the various qualities of different ships could affect each other. The idea came up to group the different types of ships into different classes of objects, with each class of objects being responsible for defining its own data and behaviors. They were later refined into Smalltalk , which was developed in Simula at Xerox PARC (the first version of which was written on Basic) but designed to be a fully dynamic system in which objects could be created and modified “on the fly” (at run time) rather than having a static program based system.

Object-oriented programming took a position as the dominant programming style in the mid-1980s, largely due to the influence of C ++ , an extension of the C programming language. Its dominance was consolidated thanks to the rise of the graphical interfaces of user, for whom object-oriented programming is particularly well suited. In this case, we also speak of event-driven programming.

Object-oriented features were added to many existing languages ​​during that time, including Ada , BASIC , Lisp , Pascal , among others. Adding these features to languages ​​that were not initially designed for them often led to code compatibility and maintainability problems. “Pure” object-oriented languages, on the other hand, lacked the features on which many programmers had come to depend. To get around this hurdle, many attempts were made to create new languages ​​based on object-oriented methods, but allowing some imperative features in “safe” ways. The eiffelof Bertrand Meyer was an early and moderately successful language with those goals but has now essentially been replaced by Java , largely because of the emergence of the Internet, and implementation of Java Virtual Machine in most browsers. PHP version 5 has been modified, it supports a complete object orientation, fulfilling all the characteristics of object orientation.

fundamental concepts

Object-oriented programming is a way of programming that tries to find a solution to these problems. It introduces new concepts, which exceed and extend old concepts already known. Among them, the following stand out:

Class

Definitions of the properties and behavior of a specific type of object. Instantiation is reading these definitions and creating an object from them.

Heritage

It is the ease by which class D inherits in it each of the attributes and operations of C, as if those attributes and operations had been defined by D. Therefore, you can use the same methods and public variables declared in C. Components registered as “private” are also inherited, but since they do not belong to the class, they are kept hidden from the programmer and can only be accessed through other public methods. This is to keep the OOP ideal hegemonic.

Object

Entity provided with a set of properties or attributes (data) and behavior or functionality (methods) which consequently react to events. It corresponds to the real objects of the world around us, or internal objects of the system (of the program). It is an instance of a class.

Method

Algorithm associated with an object (or a class of objects), the execution of which is triggered upon receipt of a “message”. From a behavioral point of view, it is what the object can do. A method can produce a change in the properties of the object, or the generation of an “event” with a new message for another object in the system.

Event

It is an event in the system (such as a user interaction with the machine, or a message sent by an object). The system handles the event by sending the appropriate message to the relevant object. It can also be defined as an event, the reaction that an object can trigger, that is, the action it generates.

Message

A communication directed to an object, which orders it to execute one of its methods with certain parameters associated with the event that generated it.

Property or attribute

Container of a type of data associated with an object (or a class of objects), which makes the data visible from outside the object and this is defined as its default characteristics, and whose value can be altered by executing some method.

Internal state

It is a variable that is declared private, that can only be accessed and altered by a method of the object, and that is used to indicate different possible situations for the object (or class of objects). It is not visible to the programmer handling an instance of the class.

Components of an object

Attributes, identity, relationships and methods.

Identification of an object

An object is represented by a table or entity that is composed of its corresponding attributes and functions.

Compared to an imperative language, a “variable” is nothing more than an internal container of the object’s attribute or an internal state, just as the “function” is an internal procedure of the object’s method.

Characteristics of OOP

There is an agreement on what characteristics “object orientation” contemplates, the following characteristics are the most important:

Abstraction

It denotes the essential characteristics of an object, where its behaviors are captured. Each object in the system serves as a model for an abstract “agent” that can do work, report and change its state, and “communicate” with other objects in the system without reveal how these features are implemented. Processes, functions or methods can also be abstracted and when they are, a variety of techniques are required to extend an abstraction. The abstraction process allows selecting relevant characteristics within a set and identifying common behaviors to define new types of entities in the real world. Abstraction is key in the object-oriented design and analysis process,

Encapsulation

It means bringing together all the elements that can be considered to belong to the same entity, at the same level of abstraction. This allows to increase the cohesion of the components of the system. Some authors confuse this concept with the concealment principle, mainly because they are often used together.

Concealment principle

Each object is isolated from the outside, is a natural module, and each type of object exposes an interface to other objects that specifies how they can interact with the objects in the class. Isolation protects the properties of an object against being modified by someone who does not have the right to access them, only the internal methods of the object can access its state. This ensures that other objects cannot change the internal state of an object in unexpected ways, eliminating unexpected side effects and interactions. Some languages ​​relax this, allowing direct access to the internal data of the object in a controlled way and limiting the degree of abstraction. The entire application is reduced to an aggregate or puzzle of objects.

Polymorphism

Different behaviors, associated with different objects, can share the same name, calling them by that name will use the behavior corresponding to the object that is being used. Or put another way, object collections and references can contain objects of different types, and invoking a behavior on a reference will produce the correct behavior for the actual type of the referenced object. When this occurs at “run time,” this last feature is called late allocation or dynamic allocation. Some languages ​​provide more static (“compile-time”) means of polymorphism, such as templates and C ++ operator overloading .

Heritage

The classes are not isolated, but are related to each other, forming a hierarchy of classification. Objects inherit the properties and behavior of all the classes to which they belong. Inheritance organizes and facilitates polymorphism and encapsulation by allowing objects to be defined and created as specialized types of pre-existing objects. They can share (and extend) their behavior without having to re-implement it. This is usually done by grouping objects in classes and these in trees or trellises that reflect a common behavior. When an object inherits from more than one class, it is said that there is multiple inheritance.

Garbage collection

Garbage collection or garbage collector is the technique by which the object environment is in charge of automatically destroying, and therefore detaching the associated memory, the objects that have been left without any reference to them. This means that the programmer does not have to worry about allocating or freeing memory, as the environment will allocate it when creating a new object and free it when no one is using it. In most hybrid languages ​​that were extended to support the Object Oriented Programming Paradigm such as C ++ or Object Pascal, this feature does not exist and memory must be manually deallocated.

Among object-oriented languages, the following stand out

  • ABAP
  • ABL Progress Software’s OpenEdge programming language
  • ActionScript
  • ActionScript 3
  • Ada
  • C ++
  • C #
  • Clarion
  • Clipper (programming language) (Version 5.x with Class (y) object library)
  • D
  • Object Pascal (Delphi)
  • Prawns
  • Harbor
  • Eiffel
  • Java
  • JavaScript (inheritance is done through prototype-based programming)
  • Lexico (in Spanish)
  • Objective-C
  • Ocaml
  • Oz
  • R
  • Perl(supports multiple inheritance. The resolution is done in preorder, but can be modified to the C3 linearization algorithm through the Class :: C3 module in CPAN)
  • PHP(as of version 5)
  • PowerBuilder
  • Python
  • Ruby
  • Smalltalk(Research project. Influenced Java.)
  • Magik (SmallWorld)
  • Vala
  • Visual BASIC .NET
  • Visual FoxPro (version 6)
  • Visual Basic 6.0
  • Visual Objects
  • XBase ++
  • DRP language
  • Scala programming language (language used by Twitter).

Many of these programming languages ​​are not purely object-oriented, but are hybrids that combine OOP with other paradigms.

Like C ++, other languages, such as OOCOBOL, OOLISP, OOPROLOG, and Object REXX, have been created by adding object-oriented extensions to a classical programming language.

A new step in the abstraction of programming paradigms is Aspect Oriented Programming (POA). Although it is still a methodology in a maturing stage, it is attracting more and more researchers and even commercial projects around the world.

 

by Abdullah Sam
I’m a teacher, researcher and writer. I write about study subjects to improve the learning of college and university students. I write top Quality study notes Mostly, Tech, Games, Education, And Solutions/Tips and Tricks. I am a person who helps students to acquire knowledge, competence or virtue.

Leave a Comment