Programming is the process of developing solutions to “live”, dynamic tasks in the form of rigid code constructions, data, functions and algorithms. The procedure for generating strict syntax from undefined semantics. Real tasks are a well-known big problem in the sense of algorithmization: in order to achieve the desired solution, the task must be placed in precise syntactic constructions.
OOP has twice attempted to “break” this ancient programming concept, but the “shackles” of the classical style of coding data and algorithms are still strong.
Level and Qualification
The computer business began with calculations, but the speed with which the acceleration of movement in the field of information processing is growing is still not large enough for classical programming to become impossible and cease to exist.
It is also objective that the developer does not insist, and the customer does not require a real solution to real problems. Both sides are accustomed to being limited by available tools and familiar features.
Forms of OOP polymorphism, ideas of code encapsulation and inheritance of properties (methods) are in the programming sphere, but not in the sphere of the problem being solved.
A good example is the PHPOffice / PHPWord library. To use it, you need the qualifications of the developer, you need to create your own system of objects, but the current level of the customer (customer requirements) is a trivial composition that the programmer blocks with his development (otherwise the requirements cannot be met). A situation like this:
In this case, the use of the library is the task of formatting documents, for example, a diploma or dissertation should be formatted according to the standard. The customer presented his requirements, and the programmer went his own way much further.
A complete analysis of the document, its assembly in the desired format, the work with tables of any level of nesting, merging and separating cells, printing in any direction, etc.
Polymorphism and OOP
There is no better definition for polymorphism than to refer to the history of the development of the idea of object-oriented programming, which is so popular now, so often used, but essentially unrealized so far.
Each author has his own concept of the beginning and essence of OOP. For each attentive reader, this concept is true and objective. But to this day, everyone takes only three positions as an unconditional axiom:
- encapsulation;
- polymorphism;
- inheritance.
Some add more: an abstraction, and most often it is this, and indeed the main point, that is used as the foundation for describing the essence of OOP.
So, opinions about OOP are polymorphic: they describe one thing, are constructed differently, or, conversely, describe different things, but are based on four identical positions.
A democratic beginning is not peculiar to the field of information technology, but we must pay tribute: the combination and coexistence of many opinions about the same thing is a real polymorphism in action.
Popular definitions of polymorphism
OOP is the next stage in the development of information technology. Few people argue with this, but its main axioms and provisions differ so much in terms of semantics that they do not deserve attention outside their totality.
- Polymorphism in programming is the ability to provide the same interface for different basic forms (data types).
- Polymorphism is the ability of objects to have a different implementation.
- Polymorphism is the ability of a function ...
- Classics (from the creator of C / C ++): "one interface - many implementations."
- Parametric polymorphism implies ...
- Polymorphism - the position of type theory ...
- Abstraction is impossible without encapsulation and inheritance, just as polymorphism is impossible without inheritance ...
One can agree that all this refers to the same thing: but the form of expression of thought, essence and content are not similar. But there is still something in common.
Essence: developer - customer
The classical development of programs involves the presence of a programmer and a task (client, customer). The programmer examines the problem, formalizes it and makes the code that leads to the solution. The customer denies all of the proposed or only part of it, indicating flaws, and the programmer does his job again.
Such a cycle of the process of solving the problem suggests that here two completely different entities are clearly combined:
- the computer cannot solve the problem itself;
- we need a program so that the computer can "understand" and "solve" the problem.
The task is the customer’s area of competence, the program is the algorithm of “adapting” the task to the capabilities of the computer - the programmer’s area of competence. The role of the latter is to “adapt” the computer to the requirements of the task, and this is superfluous!
Object-oriented programming offers to abstract . There are objects - this is the scope of the customer; there is an implementation of objects - this is the sphere of the programmer. There is no “technological" connection between the customer and the developer. The idea is cardinal, not implemented to this day, but something is already working stably.
Windows, buttons, and other objects
The history of the Air Art Technology, Object Magazine, Turbo Vision, Graph Vision - this is history. Few people remember these OOP implementations, they are practically not used and forgotten, but the window interface of Windows is familiar to millions of users, and objects in PHP, JavaScript and other languages of Internet technologies are used by hundreds of thousands of code developers, millions of visitors to web resources know about them.
This is probably the only correct way OOP should have developed: encapsulation, inheritance, polymorphism for the developer, but not for the user. Characteristically, this position was the main one when developing the visual design (interface) of Windows software, applications such as Turbo Vision and Graph Vision.
The concept behind products like the Air Art Technology and Object Magazine was significantly different. Here, the abstract object was the very first ancestor of the information structure, encapsulating information processing code on an abstract level. The objects of windows, buttons, and visual design elements were secondary here.
In the first version (Windows & etc.), the OOP paradigm: encapsulation, inheritance, polymorphism was designated at the level of the abstract ancestor, and code implementation was formed at the level of each specific descendant on the inheritance branch according to the desired structure and content.
In the second option (the Air Art Technology and Object Magazine) the level of the abstract object is important. What will happen to a particular descendant is not the point, the main thing is that its inheritance branch satisfies the requirements of all parents down to the root abstraction.
Object and system of objects: algorithm
An ideal object-oriented concept can only manipulate objects and systems of objects.
In modern programming languages, an object (class) is usually understood as a description of an object and an instance of an object, and in order to use the description of an object, languages allow the programmer to work with static objects, while a dynamic object is an instance of a description, with its unique content and structure, but using the same description methods (properties).
Current practice relates the concept of an object to a tool, that is, to a programming language, interface, access to a database, network connection, but there is nothing that indicates the interests of the customer, the problem being solved.
This is ideal for simple OOP: polymorphism makes it possible to make, in particular, a variety of design elements, but manage them with the same code. But here we are not talking about the objects of the task, which is not considered at all as an object for object-oriented analysis.
Programmers accepted OOP as a means to improve the quality and productivity of their work, but did not yield a drop of “their territory” to the customer. The basic concepts of OOP - encapsulation, inheritance, polymorphism - remained in the development field, and were not transplanted into the scope of the task.
Object and system of objects: task and solution
Computer - programmer - task. The middle link is superfluous. Ideally, there should be only two, relatively dependent, circuits: (computer - programmer) - the task. That is, the user, customer or visitor has a tool to solve his problem. How the tool is implemented, the customer does not care.
Ideally, this is just a computer that is able to understand what the customer wants and do what he wants. What it will look like: a local program or a site accessible through a browser, a special program for distributed information processing, an information system for the customer - it does not matter.
It is essential that there is no superfluous link between the task and the computer, but the first is understood and solved by the second. To achieve this goal, the computer and the customer must be connected by one system of objects, and the customer determines the meaning, structure and content of each object, and the programmer implements the methods and properties of the objects.
Ideally, when the customer’s work to create the system of objects he needs and the work to implement the methods and properties of these objects are separated in time. The farther the implementation of the system of objects (programmer) is from its semantic content (customer), the better the process.
Nothing prevents the customer and the programmer from interacting in the process of solving the problem, but a clear separation of semantics is important. Everyone should do their own thing, the programmer is not obliged to master the scope of the task, and the customer should not understand the code and, especially, the parties should not give each other advice that does not concern them.
Traditional and object programming
The basic postulates of OOP: encapsulation, inheritance, polymorphism in the form in which they became familiar and in demand, lead to a noticeable improvement in the quality and reliability of the code, significantly accelerate the work of the programmer and have a lot of other positive qualities.
But things are still there: classical programming is not inferior to its positions, and many object-oriented ideas are implemented by classical code.
However, OOP ideas and recursion led to an adequate influence on the syntax of classical syntax operators, on the logic of constructing ordinary code that has nothing to do with the object-oriented style of writing and thinking.
Lists and queues were transformed, the concept of the first and last element of the array appeared, loops “for each” appeared, and reference options for naming, use and execution became even more popular than before.
Actually, the fact that the variables have lost their “clear” face (the type of the variable can change as needed, and there is no need to describe the variable at all) says that the classics, in fact, have long become object-oriented and recognized the basic principles of OOP: encapsulation , inheritance, polymorphism as ideas of significant importance.
What is the basis: object or system
Abstraction, as the main conceptual position of OOP, regardless of where the area of responsibility (implementation) of the object is located - at the level of the first abstract object or at the level of a specific descendant - leaves the question open: where to start, from the object or from the system?
If an object is taken as the basis, it will never become a system, since the system will be inside it, and it will become a rigid image of a very concrete beginning. Here, problems arise with abstraction: the initial object accurately captures the main thing in the problem being solved, that is, it can no longer be transferred to another task.
If we put the system of objects as the basis, then we get a system of systems. It is difficult to imagine in relation to a specific task, and where to start development is also difficult to understand. By and large, OOP polymorphism with its differences in entities, forms of implementation, quantities of relevant parameters in functions gives an idea of the system that lies at the beginning, as:
- about options for solving the problem (for example, the menu);
- about the initial conditions (application of the task in different conditions, data);
- about operating modes (testing, tuning, operation).
But this and the like give him no reason to base the solution of the problem on a system of objects. Often, it is sufficient to define a single initial object.
The history of the process of solving the problem
The most important principles of OOP: polymorphism and abstraction - determine the priority of the initial object as a system of objects. In a dispute that should be earlier, a chicken or an egg, here the victory goes to the chicken.
There is no doubt that everything should begin with an abstract object, and not with a system of objects. But if we take into account the time factor and apply it at the level of each object, starting with the very first abstract, then the contradictory idea to put both the object and the system at the beginning of the solution is the only reasonable one.
If the classical programming concept in the course of solving a problem changes data, database contents, changes files, etc., then in the OOP concept polymorphism, encapsulation and time factor change the content, structure and properties of the system of objects of the problem being solved.
The programmer in OOP is least interested in the concept of a file, a database, an algorithm — this is particular, here a programmer thinks of objects, but objects exist in time and change in the course of achieving the desired.
Thus, at the beginning lies the object as a system of objects and the logic of this system is the time scale: launching a task, generating the first object, entering or collecting data, forming the next object, but nothing prevents the first object from proceeding with the next solution.
Each level of objects acts as an independent system of objects, that is, it is one object, but in the context of the process that has begun and the value of time, it is a system of objects on the time scale. For the full implementation of OOP, polymorphism, inheritance, and the time factor together provide the dynamics of the former, that is, the object can not only change over time, but also generate objects not provided by the developer, generated by the execution of tasks during the process, designed by the customer.
Real OOP polymorphism example
The complexity of the tasks, which by the power of OOP, is not comparable with that available to the classical version of writing programs. Of course, to solve any problem is always available in the usual way, but the question of how much it will “cost” time and effort often makes the result useless.
Not so long ago, the PHPOffice / PHPWord library was developed, but in order to use its capabilities, you almost always have to create your own system of objects. For example, a simple * .docx file:
is a zip archive of many files and folders in Office Open XML format (OpenXML, OOXML). Each file is written in XML tags, and when adding, changing and deleting letters, words, tables, lists, etc. elements, the contents of the files begin to be a sequence of tags that do not always contain complete elements, often one element is recorded with many tags.
If you represent this file as a sequence of tags, you get an interesting picture:
It is easy to see that the first and only paragraph of the document is represented by many tags. As for the table and the tables built into it, the scope of the description of all elements is not perceptible, but is accessible to an object-oriented application.
In fact, in the figure, green is the test output of the tags, yellow is the parameters and type of the tag, beige is the content. Created objects are oriented to machine processing. For a person, only the operations of opening a document file, its formatting and recording become available.
The solution is simple and practical, but the implementation is more focused on the computer than on the person, due to the volume of the functionality performed and the complex relationships between the objects.
OOP Region Status
The development of site management systems, server configuration and server management technologies, experience in developing dynamic sites have made object-oriented programming accessible to everyone. The problem is how to change your thinking and get used to thinking at the level of objects, and not in the context of sequentially executed code.
Usually, the transition from classical programming to object-oriented programming takes two to three months, but the costs pay off with interest. , PHP JavaScript, .
- , - , .
- . , (, ).
- , , - .
- , , , , , .