Object-Oriented Programming
Object-oriented programming (OOP) is programming primarily focused on data, data and behavior being inseparably linked. Data and behavior together constitute a class, while objects are class instances.
The components of the object-oriented approach are:
OOP considers computation as modeling of behavior. The modeled item is the object represented by computational abstractions. Suppose we want to write a well known game "Tetris". To do this, we must learn how to model the appearance of random shapes composed of four squares joined together by ribs. Also we need to regulate the falling speed of shapes, define operations of rotation and shift of shapes. Moving of shapes on the screen is limited by the DOM boundaries, this requirement must also be modeled. Besides that, filled rows of cubes must be destroyed and earned points must be counted.
Thus, this easy-to-understand game requires the creation of several models - shape model, DOM model, shape movement model and so on. All these models are abstractions, represented by calculations in the computer. To describe these models, the concept of Abstract Data Type, ADT (or complex data type) is used. Strictly speaking, the model of the "shapes" motion in the DOM is not a data type, but it is the totality of operations with the "shape" data type, using the restrictions of the "DOM" data type.
Objects are class variables. Object-oriented programming allows you to easily create and use ADT. Object-oriented programming uses the inheritance mechanism. The advance of the inheritance is in the fact that it allows obtaining derivative types from data types already defined by a user.
For example, to create Tetris shapes, it's convenient to create a base class Shape first; the other seven classes representing all of the possible shape types can be derived on its basis. Behavior of shapes is defined in the base class, while implementation of behavior of each separate shape is defined in derivative classes.
In OOP objects are responsible for their behavior. ADT developer should include a code to describe any behavior that would normally be expected from the corresponding objects. The fact that the object itself is responsible for its behavior, greatly simplifies the task of programming for the user of this object.
If we want to draw a shape on the screen, we need to know where the center will be and how to draw it. If a separate shape is well aware of how to draw itself, the programmer should send a "draw" message when using such a shape.
The MQL5 Language is a C++ like, and it also has the encapsulation mechanism for the implementation of ADT. Encapsulation combines, on the one hand, the internal details of the implementation of a particular type and, on the other hand, externally accessible functions that can influence objects of this type. Implementation details may be inaccessible for a program that uses this type.
The concept of OOP has a set of related concepts, including the following:
Some of these concepts are rather vague, some are abstract, others are of general character.
© 2000-2010, MetaQuotes Software Corp.