DynaMix (Dynamic Mixins) is a new take on polymorphism. It lets the user compose and modify polymorphic objects at run time in C++.
The library is a means to create a project's architecture rather than achieve its purpose. It focuses on maximal performance and minimal memory overhead.
DynaMix is great for the software architecture of systems with very complex objects including, but not limited to:
The library uses the type
dynamix::object as a placeholder, whose
instances can be extended with existing classes (mixins), thus providing
a particular instance with the functionality of all those types. Accessing the
newly formed type's interface is made through messages – stand-alone functions
generated by the library, which can be thought of as methods.
Here is a small example of what your code may look like if you use the library:
// assuming my_objects.get_ally(0); is a way to get an ally to the // main character in a game dynamix::object& obj = my_objects.get_ally(0); // now let's make the object think some positive thoughts about the // main character think(obj); // C++ doesn't allow us to have obj.think(). // DynaMix's messages are standalone functions // composition dynamix::mutate(obj) .add<flying_creature>(); // object can now respond to fly() fly(obj); // ...instead of obj.fly() // mutation dynamix::mutate(obj) .remove<ally>() .add<enemy>(); think(obj); // the same object now thinks negative thoughts about the main // character, since it's no longer an ally, but an enemy
Here are some of the key features of the library:
You can also check out the talk about DynaMix from C++ Russia 2018 or the article about it in ACCU's Overload Journal from April, 2018.
The following projects are known to use DynaMix as a key piece of their software architecture:
There are two more known mobile games in development which use it. They will be added to this list upon release.
The full documentation is available at the GitHub page of the library
Several small fully working annotated tutorial programs are provided with the library:
There is an accompanying
CMakeLists.txt file in the repo. Use CMake to generate project or make files for your desired platform and compiler.
Contributions in the form of issues and pull requests are welcome.
This software is distributed under the MIT Software License.
See accompanying file LICENSE or copy here.
DynaMix was initially developed as Boost.Mixin but is now a separate library, that doesn't depend on the Boost libraries Collection.
DynaMix, unlike Boost.Mixin, has no C++98 support. It's C++11 only.
DynaMix is distributed under the MIT license, whereas Boost.Mixin is distributed under the Boost Software License.