Added template decorator pattern

This commit is contained in:
Bartek Kryza
2021-07-25 22:51:46 +02:00
parent 16e60ec8c5
commit ee753f5595
11 changed files with 221 additions and 2 deletions

View File

@@ -25,6 +25,7 @@
* [t00024](./test_cases/t00024.md) - Proxy pattern
* [t00025](./test_cases/t00025.md) - Template proxy pattern
* [t00026](./test_cases/t00026.md) - Template memento pattern
* [t00027](./test_cases/t00027.md) - Template decorator pattern
## Sequence diagrams
* [t20001](./test_cases/t20001.md) - Basic sequence diagram
## Configuration diagrams

View File

@@ -74,7 +74,6 @@ struct StringMemento {
Caretaker<std::string> caretaker;
Originator<std::string> originator;
};
}
}

79
docs/test_cases/t00027.md Normal file
View File

@@ -0,0 +1,79 @@
# t00027 - Template decorator pattern
## Config
```yaml
compilation_database_dir: ..
output_directory: puml
diagrams:
t00027_class:
type: class
glob:
- ../../tests/t00027/t00027.cc
using_namespace:
- clanguml::t00027
include:
namespaces:
- clanguml::t00027
```
## Source code
File t00027.cc
```cpp
#include <memory>
#include <tuple>
#include <type_traits>
namespace clanguml {
namespace t00027 {
class Shape {
public:
virtual void display() = 0;
virtual ~Shape() = default;
};
template <template <typename> class... T>
class Line : public Shape, public T<Line<>>... {
public:
void display() override
{
std::apply([](auto &&... x) { (x.display(), ...); },
std::forward_as_tuple(T<Line<>>()...));
}
};
template <template <typename> class... T>
class Text : public Shape, public T<Text<>>... {
public:
void display() override
{
std::apply([](auto &&... x) { (x.display(), ...); },
std::forward_as_tuple(T<Text<>>()...));
}
};
struct ShapeDecorator {
virtual void display() = 0;
};
template <typename T> class Color : public ShapeDecorator {
public:
void display() override {}
};
template <typename T> class Weight : public ShapeDecorator {
public:
void display() override {}
};
struct Window {
Line<Color, Weight> border;
Line<Color> divider;
Text<Color, Weight> title;
Text<Color> description;
};
}
}
```
## Generated UML diagrams
![t00027_class](./t00027_class.png "Template decorator pattern")

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB