====== Object-oriented vs. async design - friends or foes? ====== ===== Introduction ===== Nowadays object-oriented design is one of the most commonly used approach in software design and the majority of most popular programming languages have support object-oriented paradigm. Another concept in programing which is gaining popularity during last decades is asynchronous programming which is also implemented in many popular frameworks for different programming languages. These two concepts consider different issues: object-oriented design describes how keeping and processing program’s data should be organized whereas asynchronous design deals with distributing and scheduling execution of the program’s tasks. But are these two design approaches compatible with each other? This essay analyses if the principles dictated by object-oriented and asynchronous design can both be sticked to in software design and are there enough modeling and programming tools for combining these concepts. ===== Tell, don’t ask ===== One of the principles which are recommended to stick to during Object-oriented development is “Tell, don’t ask” which was primary described in IEEE Software column [1]. This article emphasizes on the fact that developing in object-oriented paradigm means that all logic of processing the object’s data is implemented in the object’s methods and the main program just calls the corresponding methods. The callee does not have access to the object’s fields and adopt decisions based on the data’s values – this is responsibility of the objects’ methods. Pretty same concept is realized in asynchronous programming. In fact, calling an asynchronous function means that another instance is asked to do something and it is assumed that the executed function has access to all data which is required to be processed. Consequently, the solution to execute a class’s method in asynchronous context fits both object-oriented and asynchronous design as a method of a class implements a meaningful action and calling it in asynchronous context just means to execute a task asynchronously. ===== What about notation? ===== A lot of approaches to modeling asynchronous behavior in object-oriented paradigm described in the literature. For instance, sequence diagrams which describe communication between objects include symbols that depict asynchronous messages. The notation can be found in different sequence diagram tutorials, for instance in [2]. Moreover, UML2 provide notation for sending and receiving asynchronous messages between the components’ interfaces. This is also described in different UML2 tutorials and books, for example [3] and [4]. Apart from generally recognized UML2 notation there exist another notation for object-oriented design including asynchrony which is introduced in [5]. The authors explain their decision to develop symbols for depicting asynchronous processes with the fact that software systems’ components interact with each other and frequently do it in asynchronous way. As it can be seen from the overview of languages for modeling object-oriented systems, they contain tools for including asynchronous interaction in the designed system. Consequently, asynchrony can be brought to the system at stage of design which allow software engineers to plan interaction between objects properly at early steps of development and acquire better understanding of how the system should work. In sum, in terms of design and modeling object-oriented and asynchronous design can not be foes as there are a lot of ways to include asynchronous interaction in software system’s model that supposes that asynchronously can be used along with object-oriented design. ===== Continue talking about design ===== One of the steps in designing software system is detailed design which implies applying design patterns. Are there any patterns for asynchronous design? Actually, several design patterns for asynchronous object-oriented systems are described in Java and C# documentation ([6], [7]). For instance, “Async Method Invocation” pattern describes how the results of executing of an asynchronous task can be returned to the callee later in case of immediate return of the asynchronous function. Consequently, some typical problems which are likely to be faced to during designing an asynchronous object-oriented system can be solved with design patterns and there exist correct approaches to object-oriented asynchronous design. ===== Real life examples ===== Let us consider several examples where asynchronous design coexists with object-oriented design in real programming languages and frameworks. First of all, one of the most famous and widely used C++ library for asynchrony Boost.Asio ([8]) is written in object-oriented style. In this library all concepts used in asynchronous programming are implemented as classes and all asynchronous operations under them can be done by calling corresponding methods of the objects. Another programing language which supports asynchronous paradigm is Java ([9]). Since Java implies usage of object-oriented paradigm, all asynchronous Java applications combine object-oriented and asynchronous design. Moreover, one of the most popular Java frameworks Spring supports asynchronous applications. The same thing is for C#: this language also supports only object-oriented paradigm and allows writing asynchronous applications ([10]). And the number of such applications is rather great: according to the research hold in [11], there are more than 1300 open-source asynchronous C# mobile applications. ===== Conclusion ===== To sum up, the basic principles of object-oriented paradigm and asynchrony do not contradict to each other and can be easily combined in one software system. Both designing tools and programming languages allow developers to make their object-oriented systems asynchronous at stage of design and implement them in such way. As object-oriented and asynchronous design are both modern standards of software systems due to their advantages, both these approaches are used in a lot of applications written in different programming languages. Answering the question from the topic of the essay: object-oriented and asynchronous design are certainly friends. ===== References ===== - Hunt A., Thomas D. The art of enbugging IEEE Software. 2003. Т. 20. – №. 1. – С. 10-11 - UML Sequence diagram tutorial. URL: https://sparxsystems.com/resources/tutorials/uml2/sequence-diagram.html (access date: 19.12.21) - Rensink A., Warmer J. Model Driven Architecture-Foundations and Applications. – Springer, 2006 - UML Component diagram tutorial. URL: https://sparxsystems.com/resources/tutorials/uml2/component-diagram.html (access date: 19.12.21) - Wasserman A. I., Pircher P. A., Muller R. J. The object-oriented structured design notation for software design representation Computer. – 1990. – Т. 23. – №. 3. – С. 50-63. - Java design patterns for asynchronous programming. URL: https://java-design-patterns.com/patterns/async-method-invocation/ (access date: 19.12.21) - C# design patterns for asynchronous programming. URL: https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/ (access date: 19.12.21) - Boost documentation. URL: https://www.boost.org/doc/libs/1_78_0/doc/html/boost_asio.html (access date: 19.12.21) - Asynchronous programming in Java. URL: https://spring.io/guides/gs/async-method/ (access date: 19.12.21) - Asynchronous programming in C#: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/ (access date: 19.12.21) - Okur S. et al. A study and toolkit for asynchronous programming in C# //Proceedings of the 36th International Conference on Software Engineering. – 2014. – С. 1117-1127.