До питання створення статичного патерну проєктування для подвійної диспетчеризації модельних сигнатур
Loading...
Date
2021-12-10
Authors
Бублик, Володимир
Journal Title
Journal ISSN
Volume Title
Publisher
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.
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.
Description
Keywords
С, об’єктно-орієнтоване програмування, патерн (зразок) проєктування, подвійна диспетчеризація (мультиметод), віртуальна функція, поліморфізм, узагальнене програмування, стаття, C, object-oriented programming, design pattern, double dispatching (multimethod), virtual function, polymorphism, generalized programming, article
Citation
Бублик В.В. До питання створення статичного патерну проєктування для подвійної диспетчеризації модельних сигнатур / Бублик В. В. // Наукові записки НаУКМА. Комп'ютерні науки. - 2021. - Т. 4. - С. 64-71. - https://doi.org/10.18523/2617-3808.2021.4.64-71