Files
clang-uml/docs/test_cases/t00023.md
2023-12-09 20:16:28 +01:00

430 lines
11 KiB
Markdown

# t00023 - Strategy pattern
## Config
```yaml
diagrams:
t00023_class:
type: class
glob:
- t00023.cc
using_namespace: clanguml::t00023
include:
namespaces:
- clanguml::t00023
```
## Source code
File t00023.cc
```cpp
#include <memory>
namespace clanguml {
namespace t00023 {
class Strategy {
public:
virtual ~Strategy() = default;
virtual void algorithm() = 0;
};
class StrategyA : public Strategy {
public:
void algorithm() override { }
};
class StrategyB : public Strategy {
public:
void algorithm() override { }
};
class StrategyC : public Strategy {
public:
void algorithm() override { }
};
class Context {
public:
Context(std::unique_ptr<Strategy> strategy)
: m_strategy(std::move(strategy))
{
}
void apply() { m_strategy->algorithm(); }
private:
std::unique_ptr<Strategy> m_strategy;
};
} // namespace t00023
} // namespace clanguml
```
## Generated PlantUML diagrams
![t00023_class](./t00023_class.svg "Strategy pattern")
## Generated Mermaid diagrams
![t00023_class](./t00023_class_mermaid.svg "Strategy pattern")
## Generated JSON models
```json
{
"diagram_type": "class",
"elements": [
{
"bases": [],
"display_name": "clanguml::t00023::Strategy",
"id": "1469857696438841976",
"is_abstract": true,
"is_nested": false,
"is_struct": false,
"is_template": false,
"is_union": false,
"members": [],
"methods": [
{
"access": "public",
"is_const": false,
"is_consteval": false,
"is_constexpr": true,
"is_constructor": false,
"is_copy_assignment": false,
"is_defaulted": true,
"is_deleted": false,
"is_move_assignment": false,
"is_noexcept": false,
"is_operator": false,
"is_pure_virtual": false,
"is_static": false,
"is_virtual": true,
"name": "~Strategy",
"parameters": [],
"source_location": {
"column": 13,
"file": "t00023.cc",
"line": 8,
"translation_unit": "t00023.cc"
},
"type": "void"
},
{
"access": "public",
"is_const": false,
"is_consteval": false,
"is_constexpr": false,
"is_constructor": false,
"is_copy_assignment": false,
"is_defaulted": false,
"is_deleted": false,
"is_move_assignment": false,
"is_noexcept": false,
"is_operator": false,
"is_pure_virtual": true,
"is_static": false,
"is_virtual": true,
"name": "algorithm",
"parameters": [],
"source_location": {
"column": 18,
"file": "t00023.cc",
"line": 9,
"translation_unit": "t00023.cc"
},
"type": "void"
}
],
"name": "Strategy",
"namespace": "clanguml::t00023",
"source_location": {
"column": 7,
"file": "t00023.cc",
"line": 6,
"translation_unit": "t00023.cc"
},
"template_parameters": [],
"type": "class"
},
{
"bases": [
{
"access": "public",
"id": "1469857696438841976",
"is_virtual": false,
"name": "clanguml::t00023::Strategy"
}
],
"display_name": "clanguml::t00023::StrategyA",
"id": "1245533075819635385",
"is_abstract": false,
"is_nested": false,
"is_struct": false,
"is_template": false,
"is_union": false,
"members": [],
"methods": [
{
"access": "public",
"is_const": false,
"is_consteval": false,
"is_constexpr": false,
"is_constructor": false,
"is_copy_assignment": false,
"is_defaulted": false,
"is_deleted": false,
"is_move_assignment": false,
"is_noexcept": false,
"is_operator": false,
"is_pure_virtual": false,
"is_static": false,
"is_virtual": true,
"name": "algorithm",
"parameters": [],
"source_location": {
"column": 10,
"file": "t00023.cc",
"line": 14,
"translation_unit": "t00023.cc"
},
"type": "void"
}
],
"name": "StrategyA",
"namespace": "clanguml::t00023",
"source_location": {
"column": 7,
"file": "t00023.cc",
"line": 12,
"translation_unit": "t00023.cc"
},
"template_parameters": [],
"type": "class"
},
{
"bases": [
{
"access": "public",
"id": "1469857696438841976",
"is_virtual": false,
"name": "clanguml::t00023::Strategy"
}
],
"display_name": "clanguml::t00023::StrategyB",
"id": "264986406899645",
"is_abstract": false,
"is_nested": false,
"is_struct": false,
"is_template": false,
"is_union": false,
"members": [],
"methods": [
{
"access": "public",
"is_const": false,
"is_consteval": false,
"is_constexpr": false,
"is_constructor": false,
"is_copy_assignment": false,
"is_defaulted": false,
"is_deleted": false,
"is_move_assignment": false,
"is_noexcept": false,
"is_operator": false,
"is_pure_virtual": false,
"is_static": false,
"is_virtual": true,
"name": "algorithm",
"parameters": [],
"source_location": {
"column": 10,
"file": "t00023.cc",
"line": 19,
"translation_unit": "t00023.cc"
},
"type": "void"
}
],
"name": "StrategyB",
"namespace": "clanguml::t00023",
"source_location": {
"column": 7,
"file": "t00023.cc",
"line": 17,
"translation_unit": "t00023.cc"
},
"template_parameters": [],
"type": "class"
},
{
"bases": [
{
"access": "public",
"id": "1469857696438841976",
"is_virtual": false,
"name": "clanguml::t00023::Strategy"
}
],
"display_name": "clanguml::t00023::StrategyC",
"id": "174795176193483089",
"is_abstract": false,
"is_nested": false,
"is_struct": false,
"is_template": false,
"is_union": false,
"members": [],
"methods": [
{
"access": "public",
"is_const": false,
"is_consteval": false,
"is_constexpr": false,
"is_constructor": false,
"is_copy_assignment": false,
"is_defaulted": false,
"is_deleted": false,
"is_move_assignment": false,
"is_noexcept": false,
"is_operator": false,
"is_pure_virtual": false,
"is_static": false,
"is_virtual": true,
"name": "algorithm",
"parameters": [],
"source_location": {
"column": 10,
"file": "t00023.cc",
"line": 24,
"translation_unit": "t00023.cc"
},
"type": "void"
}
],
"name": "StrategyC",
"namespace": "clanguml::t00023",
"source_location": {
"column": 7,
"file": "t00023.cc",
"line": 22,
"translation_unit": "t00023.cc"
},
"template_parameters": [],
"type": "class"
},
{
"bases": [],
"display_name": "clanguml::t00023::Context",
"id": "2038594012979479050",
"is_abstract": false,
"is_nested": false,
"is_struct": false,
"is_template": false,
"is_union": false,
"members": [
{
"access": "private",
"is_static": false,
"name": "m_strategy",
"source_location": {
"column": 31,
"file": "t00023.cc",
"line": 37,
"translation_unit": "t00023.cc"
},
"type": "std::unique_ptr<Strategy>"
}
],
"methods": [
{
"access": "public",
"is_const": false,
"is_consteval": false,
"is_constexpr": false,
"is_constructor": true,
"is_copy_assignment": false,
"is_defaulted": false,
"is_deleted": false,
"is_move_assignment": false,
"is_noexcept": false,
"is_operator": false,
"is_pure_virtual": false,
"is_static": false,
"is_virtual": false,
"name": "Context",
"parameters": [
{
"name": "strategy",
"type": "std::unique_ptr<Strategy>"
}
],
"source_location": {
"column": 5,
"file": "t00023.cc",
"line": 29,
"translation_unit": "t00023.cc"
},
"type": "void"
},
{
"access": "public",
"is_const": false,
"is_consteval": false,
"is_constexpr": false,
"is_constructor": false,
"is_copy_assignment": false,
"is_defaulted": false,
"is_deleted": false,
"is_move_assignment": false,
"is_noexcept": false,
"is_operator": false,
"is_pure_virtual": false,
"is_static": false,
"is_virtual": false,
"name": "apply",
"parameters": [],
"source_location": {
"column": 10,
"file": "t00023.cc",
"line": 34,
"translation_unit": "t00023.cc"
},
"type": "void"
}
],
"name": "Context",
"namespace": "clanguml::t00023",
"source_location": {
"column": 7,
"file": "t00023.cc",
"line": 27,
"translation_unit": "t00023.cc"
},
"template_parameters": [],
"type": "class"
}
],
"name": "t00023_class",
"relationships": [
{
"access": "public",
"destination": "1469857696438841976",
"source": "1245533075819635385",
"type": "extension"
},
{
"access": "public",
"destination": "1469857696438841976",
"source": "264986406899645",
"type": "extension"
},
{
"access": "public",
"destination": "1469857696438841976",
"source": "174795176193483089",
"type": "extension"
},
{
"access": "private",
"destination": "1469857696438841976",
"label": "m_strategy",
"source": "2038594012979479050",
"type": "aggregation"
}
],
"using_namespace": "clanguml::t00023"
}
```