Abstract

The paper investigates a possibility of developing a non-virtual hierarchy for a special case of class signature, which may possess different interpretations. The approach is similar to double dispatching in the C ++ programming language. As an alternative to polymorphism, a non-polymorphic hierarchy has been suggested based on generic programming templates. This hierarchy is based on inverse parametrization for templates enabling constructing a general scheme for the design pattern. The pattern defined a class architecture suitable for static implementation of double dispatched multimethod for a special case of signature- defined interfaces.In fact, any abstract base class (interface) with purely virtual operations must acquire a polymorphic implementation. Besides, the polymorphism itself, the dependence of a virtual function on two objects – “this” and another parameter – requires the use of double dispatch, turning a class member function into a double dispatched multimethod.A preliminary consideration deals with issues of double dispatching in the C++ programming language. Inheritance with polymorphic class member functions is used. This requires special efforts of adding to both bases and derived classes a couple of virtual functions to support dispatching. In any case, this approach, besides using virtual functions, has a disadvantage of violating one of the SOLID principles, namely the principle of dependency inversion: base classes should not depend on derivatives, which negatively affects the quality of the software.Polymorphism is usually understood as the dynamic tuning of a program to the data type of the object that the program will encounter during its execution. That is, by its nature, polymorphism is a purely dynamic characteristic. However, in C++ literature and in practice, you can come across the term “static polymorphism”.At the same time, research of possibilities of generalized programming (templates) allows transferring some dynamic problems to the static level. In particular, a variant of static polymorphism application without virtual functions can be considered.A variant of non-virtual double scheduling has been proposed, generalized in the form of a created design pattern “Signature multimethod”. The use of the newly created pattern is illustrated with an example of implementing classes of complex numbers. The absence of violations of SOLID principles is shown, and the possibility of supplementing the hierarchy with new derived classes without the need to interfere with the structure of the base class is demonstrated.The approach suggested in this work has been used in courses in object-oriented programming at the Faculty of Informatics of Kyiv-Mohyla Academy.

Highlights

  • У роботі досліджено можливість уникнення застосування поліморфізму при створенні мовою програмування С++ класів-моделей певної сигнатури, придатних для подвійної диспетчеризації функцій–членів цих класів стосовно варіантів їх інтерпретації

  • Але кожного разу за потреби доповнення ієрархії новими похідними класами доведеться вносити зміни до самого базового класу

  • In any case, this approach, besides using virtual functions, has a disadvantage of violating one of the SOLID principles, namely the principle of dependency inversion: base classes should not depend on derivatives, which negatively affects the quality of the software

Read more

Summary

МОДЕЛЬНИХ СИГНАТУР

У роботі досліджено можливість уникнення застосування поліморфізму при створенні мовою програмування С++ класів-моделей певної сигнатури, придатних для подвійної диспетчеризації функцій–членів цих класів стосовно варіантів їх інтерпретації. Розглянуто приклад застосування патерну для спільної реалізації мультиметодів у різнорідних класах на прикладі комплексних чисел і рядків символів. AComplex a(3.5, 2); TComplex t1(1, pi), t2(1, pi/4); вирази a + t1; t1+a; t1+t2 обчислюються зведенням типів за допомогою однієї і тієї самої реалізації операції додавання + для класу AComplex. В. До питання створення статичного патерну проєктування для подвійної диспетчеризації модельних сигнатур то, через несиметричність першого параметра з другим, зведення за першим параметром даватиме синтаксичну помилку, тож вирази t1+a і t1+t2 стануть помилковими. При цьому адитивні операції над числами у тригонометричній формі можуть і надалі застосовувати алгебричні реалізації за явного зведення типів.

Особливості створення динамічних мультиметодів
Створення невіртуальної диспетчеризації
Список літератури
TOWARDS CREATING A STATIC DESIGN PATTERN FOR DOUBLE DISPATCHING MODEL SIGNATURES
Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call