Object-oriented programming
The object-oriented programming (OOP, in Spanish); is a programming paradigm based on the concept of "objects" as a base, which contain information in the form of fields (sometimes also referred to as attributes or properties) and code in the form of methods.
Objects are able to interact and modify the values contained in their fields or attributes (state) through their methods (behavior).
Many of the pre-designed objects of current programming languages allow grouping into libraries or libraries, however, many of these languages allow the user to create their own libraries.
Some key features of object-oriented programming are inheritance, cohesion, abstraction, polymorphism, coupling, and encapsulation.
Its use became popular in the early 1990s. Currently, there is a wide variety of programming languages that support object orientation, most of which are based on the concept of classes and instances.
Introduction
Objects are entities that have a certain state, behavior and identity:
- Identity is a property of an object that differentiates it from the rest; said with other words, it is your identifier (concept analogous to the identifier of a variable or a constant).
- The methods and fields are closely related to the whole property. This property highlights that a class requires methods to deal with the fields it counts with.
Object-oriented programming 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 data. Structured programming gives priority to the concept of procedures or functions over that of structures (mainly functions that process data are used). Object-oriented programming, on the other hand, first defines the objects or structures to later request the execution of their methods.
Origin
OOP concepts originate from Simula 67, a language designed for simulations, created by Ole-Johan Dahl and Kristen Nygaard of the Norwegian Computing Center in Oslo. This center worked on ship simulations, which were confounded by the combinatorial explosion of how the various qualities of different ships could affect one another. The idea came from grouping the various types of ships into various object classes, each object class being responsible for defining its 'own' object classes. data and behaviors. They were later refined in Smalltalk, developed in Simula at Xerox PARC (whose first version was written on top of Basic) but designed to be a completely dynamic system in which objects could be created and modified "on the fly" (at runtime) instead of having a system based on static programs.
OOP became 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 further consolidated by the rise of graphical interfaces of users, for which OOP is particularly well adapted. In this case, we also talk about event-driven programming.
Object-oriented features were added to many existing languages during that time, including Ada, BASIC, Lisp plus Pascal, among others. Adding these features to languages that were not initially designed for them often led to code maintainability and compatibility 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. Bertrand Meyer's Eiffel programming language was an early and moderately successful language for those goals, but has now been essentially superseded by Java, largely due to the advent of the Internet and the implementation of the Java virtual machine in most browsers. Web. PHP in its version 5 has been modified; supports a complete orientation to objects, fulfilling all the characteristics of object orientation.
History
The terminology "objects" and "oriented" in the modern sense of object-oriented programming made its first appearance at MIT in the late 1950s and early 1960s. Already in 1960 in the environment of the artificial intelligence group, the term "object" was used to refer to elements (LISP atoms) with properties (attributes);
Another early example of MIT-oriented programming was Sketchpad created by Ivan Sutherland in 1960–1961; In the glossary of the 1963 technical report, Sutherland defines the notion of "object" and of "instance".
Simula introduced important concepts that are an essential part of object-oriented programming today, such as classes, objects, inheritance, and dynamic binding.
More recently, a number of languages have emerged that are primarily object-oriented but also support procedural programming. Two examples of these languages are Python and Ruby. Probably the most commercially important recent object-oriented languages are Java, developed by Sun Microsystems, and C# along with Visual Basic.NET (VB.NET), designed by Microsoft's.
Fundamental concepts
OOP is a way of programming that tries to find a solution to these problems. It introduces new concepts, which go beyond and extend already known old concepts. Among them are the following:
- Class
- A class is a kind of "plant" in which predetermined attributes and methods of an object type are defined. This template is created to create objects easily. The method of creating new objects by reading and recovering the attributes and methods of a class is known as instance.
- Inheritance
- For example, class C heritage to class D, is the ease by which class D inherited in it each of the attributes and operations of C, as if those attributes and operations had been defined by the same D. Therefore, you can use the same methods and variables as "public" (public) in C. The components recorded as "private" (private) are also inherited but kept hidden from the programmer and can only be accessed through other public methods. In order to access an attribute or operation of a class in any of its subclasses but to keep it hidden for other classes it is necessary to register the components as "protected" (protected), in this way they will be visible in C and D but not in other classes.
- Object
- Instance of a class. Entity provided with a set of properties or attributes (data) and behavior or functionality (methods), the same that consequently react to events. They correspond to the real objects of the world that surrounds us, or with internal objects of the system (of the program).
- Method
- Algorithm associated with an object (or a class of objects), whose execution is triggered after receiving a "message". From the point of view of behavior, 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 of 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. You can also define as an event the reaction that can trigger an object; that is, the action it generates.
- Attributes
- Characteristics the class has.
- Message
- A communication addressed 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 the execution of some method.
- Internal State
- It is a variable that is declared private, which can only be accessed and altered by an object method, and which is used to indicate different situations possible for the object (or object class). It is not visible to the programmer who handles a class instance.
- Members of an object
- Attributes, identity, relationships and methods.
- Identification of an object
- An object is represented by a table or entity consisting of its attributes and corresponding functions.
In comparison to an imperative language, a "variable" is nothing more than an internal container of the object attribute or an internal state, as well as the "function" is an internal procedure of the object's method.
Characteristics of OOP
There is agreement about what features "object-oriented" contemplates. The following features are the most important:
- Abstract
- It denotes the essential characteristics of an object, where its behaviors are captured. Each object in the system serves as a model of an abstract "agent" that can perform work, report and change its state, and "communicate" with other objects in the system without revealing "how" these characteristics are implemented. Processes, functions or methods may also be abstracted, and, when they are, a variety of techniques are required to expand abstraction. The abstraction process allows you to select the relevant features within a set and identify common behaviors to define new types of entities in the real world. Abstraction is key in the process of object-oriented analysis and design, as through it we can come to put together a set of classes that will allow us to model the reality or problem that we want to attack.
- Encapsulation
- It means gathering all elements that can be considered belonging to the same entity, at the same level of abstraction. This allows to increase the cohesion (structured design) of the components of the system. Some authors confuse this concept with the principle of concealment, mainly because they are usually used together.
- Polimorphism
- Different behaviors, associated with different objects, can share the same name; by calling them by that name the behavior corresponding to the object being used will be used. Or, said otherwise, references and collections of objects may contain objects of different types, and the invocation of a behavior in a reference will produce the correct behavior for the actual type of the referenced object. When this occurs in "execution time", this last feature is called late assignment or dynamic assignment. Some languages provide more static means (in "built time") of polymorphism, such as templates and overload of C++ operators.
- Inheritance
- Classes are not isolated, but relate to each other, forming a ranking hierarchy. Objects inherit the properties and behavior of all classes to which they belong. The heritage organizes and facilitates polymorphism and encapsulation, allowing objects to be defined and created as specialized types of pre-existing objects. These may share (and extend) their behavior without having to re-implement it. This is usually done by grouping objects into classes, and these in trees or roofs that reflect common behavior. When an object inherited from more than one class, it is said that there is multiple inheritance; it is of high technical complexity so that virtual inheritance is often used to avoid duplication of data.
- Modularity
- It is called "modularity" to the property that allows to subdivid an application into smaller parts (called modules), each of which must be as independent as possible from the application itself and the other parts. These modules can be compiled separately, but have connections with other modules. Like encapsulation, languages support modularity in various forms.
- Principle of concealment
- Each object is isolated from the outside, it is a natural module, and each type of object exposes an "interface" to other objects that details how they can interact with the objects of the class. Insulation protects the properties of an object against its modification by those who have no right to access them; only the internal methods of the object can access their status. This ensures that other objects cannot change the inner state of an object unexpectedly, eliminating side effects and unexpected interactions. Some languages relax this, allowing direct access to the internal data of the object in a controlled manner and limiting the degree of abstraction. The entire application is reduced to an aggregate or object puzzle.
- Waste collection
- The garbage collection (garbage collection) is the technique by which the object environment is responsible for automatically destroying, and therefore disconnecting the associated memory, the objects that have been left without any reference to them. This means that the programmer should not worry about mapping or memory release, as the environment will assign it to create a new object and release it when no one is using it. In most of the hybrid languages that spread to support the Paradigm of Orientated Programming to Objects such as C++ or Object Pascal, this characteristic does not exist and memory must be expressly dissigned.
Criticism
The OOP paradigm has been criticized for various reasons, including not meeting the goals of reusability and modularity, and for overemphasizing one aspect of software design and modeling (data/objects) at the expense of other important aspects (computing). /algorithms).
Summary
OOP is a paradigm that emerged in the 1970s, which uses objects as fundamental elements in the construction of the solution. An object is an abstraction of some fact or entity in the real world, with attributes that represent its characteristics or properties, and methods that emulate its behavior or activity. All properties and methods common to objects are encapsulated or grouped into classes. A class is a template, a prototype for creating objects; in general, each object is said to be an instance or instance of a class.
Types
To carry out object-oriented programming there are 3 main streams:
- Based on classes. It is the most widely used by object-oriented programming languages. For example, it is used by Java, C++ and C#. It is based on creating a mould structure called class where the fields and methods that will have our objects are specified. Every time we need an object we create an instance (or copy of the object) using the class as a mould.
- Based on prototypes.- It is supported by Javascript, Python and Ruby. There are no classes, there are only objects. The mechanism for reuse is given by the cloning of objects. Objects are created directly and when you want to generate another with the same structure cloning is used. Once cloned if we want we can add the required fields and methods. A prototypical object is an object that is used as a template from which the initial set of properties of an object is obtained. Any object can be used as the prototype of another object, allowing the second object to share the properties of the first.
- Based on structures.- Supported by Go, Rust, Nim and some other compiled languages. This approach is based on the construction of types defined by the user (struct type), called structures with their respective properties or attributes and is added a pointer variable to the functions or methods of that structure. It has support of public and private methods, as well as Generics. It also has interface support; support pillar for polymorphism and heritage.
Some object-oriented languages
Simula (1967) is accepted as the first language to possess the main features of an object-oriented language. It was created to make simulation programs, where the "objects" They are the representation of the most important information.
Smalltalk (1972 to 1980) is arguably the canonical example, and from which much of object-oriented programming theory has been developed.
Object-oriented languages include the following:
- ABAP
- ABL
- ActionScript
- ActionScript 3
- C#
- Clarion
- Clipper
- D
- Object Pascal (Embarcadero Delphi)
- Gambas
- GObject
- Genie
- Harbour
- Eiffel
- Fortran 90/95
- Java
- JavaScript
- Léxico
- Objective-C
- Ocaml
- Oz
- R
- Pauscal (in Spanish)
- Perl
- Perl 6
- PHP
- PowerScript
- Processing.
- Python
- Ruby
- Self
- Smalltalk
- Swift
- Magik
- Vala
- VB.NET
- Visual FoxPro
- Visual Basic 6.0
- Visual DataFlex
- Visual Objects
- XBase+
- DRP
- Scala
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 classic programming language.
A new step in the abstraction of programming paradigms is Aspect Oriented Programming (AOP). Although it is still a maturing methodology, it is attracting more and more researchers and even commercial projects around the world.
Contenido relacionado
SkyOS
Concentrator
Operating system