# t00021 - Visitor pattern
## Config
```yaml
compilation_database_dir: ..
output_directory: puml
diagrams:
  t00021_class:
    type: class
    glob:
      - ../../tests/t00021/t00021.cc
    using_namespace:
      - clanguml::t00021
    include:
      namespaces:
        - clanguml::t00021

```
## Source code
File t00021.cc
```cpp
#include <memory>

namespace clanguml {
namespace t00021 {

class A;
class B;

class Visitor {
public:
    virtual ~Visitor() = default;
    virtual void visit_A(const A &item) const = 0;
    virtual void visit_B(const B &item) const = 0;
};

class Visitor1 : public Visitor {
public:
    void visit_A(const A &item) const override { }
    void visit_B(const B &item) const override { }
};

class Visitor2 : public Visitor {
public:
    void visit_A(const A &item) const override { }
    void visit_B(const B &item) const override { }
};

class Visitor3 : public Visitor {
public:
    void visit_A(const A &item) const override { }
    void visit_B(const B &item) const override { }
};

class Item {
public:
    virtual ~Item() = default;
    virtual void accept(const Visitor &visitor) const = 0;
};

class A : public Item {
public:
    void accept(const Visitor &visitor) const override { }
};

class B : public Item {
public:
    void accept(const Visitor &visitor) const override { }
};
} // namespace t00021
} // namespace clanguml

```
## Generated UML diagrams
![t00021_class](./t00021_class.svg "Visitor pattern")
## Generated JSON models
```json
{
  "diagram_type": "class",
  "elements": [
    {
      "bases": [],
      "display_name": "clanguml::t00021::Visitor",
      "id": "1668671110672744395",
      "is_abstract": true,
      "is_nested": false,
      "is_struct": false,
      "is_template": false,
      "is_union": false,
      "members": [],
      "methods": [
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": true,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "~Visitor",
          "parameters": [],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": true,
          "is_static": false,
          "is_virtual": true,
          "name": "visit_A",
          "parameters": [
            {
              "name": "item",
              "type": "const clanguml::t00021::A &"
            }
          ],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": true,
          "is_static": false,
          "is_virtual": true,
          "name": "visit_B",
          "parameters": [
            {
              "name": "item",
              "type": "const clanguml::t00021::B &"
            }
          ],
          "type": "void"
        }
      ],
      "name": "Visitor",
      "namespace": "clanguml::t00021",
      "source_location": {
        "file": "../../tests/t00021/t00021.cc",
        "line": 9
      },
      "template_parameters": [],
      "type": "class"
    },
    {
      "bases": [
        {
          "access": "public",
          "id": "1668671110672744395",
          "is_virtual": false,
          "name": "clanguml::t00021::Visitor"
        }
      ],
      "display_name": "clanguml::t00021::Visitor1",
      "id": "1028369219400401946",
      "is_abstract": false,
      "is_nested": false,
      "is_struct": false,
      "is_template": false,
      "is_union": false,
      "members": [],
      "methods": [
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "visit_A",
          "parameters": [
            {
              "name": "item",
              "type": "const clanguml::t00021::A &"
            }
          ],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "visit_B",
          "parameters": [
            {
              "name": "item",
              "type": "const clanguml::t00021::B &"
            }
          ],
          "type": "void"
        }
      ],
      "name": "Visitor1",
      "namespace": "clanguml::t00021",
      "source_location": {
        "file": "../../tests/t00021/t00021.cc",
        "line": 16
      },
      "template_parameters": [],
      "type": "class"
    },
    {
      "bases": [
        {
          "access": "public",
          "id": "1668671110672744395",
          "is_virtual": false,
          "name": "clanguml::t00021::Visitor"
        }
      ],
      "display_name": "clanguml::t00021::Visitor2",
      "id": "1710373315476287130",
      "is_abstract": false,
      "is_nested": false,
      "is_struct": false,
      "is_template": false,
      "is_union": false,
      "members": [],
      "methods": [
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "visit_A",
          "parameters": [
            {
              "name": "item",
              "type": "const clanguml::t00021::A &"
            }
          ],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "visit_B",
          "parameters": [
            {
              "name": "item",
              "type": "const clanguml::t00021::B &"
            }
          ],
          "type": "void"
        }
      ],
      "name": "Visitor2",
      "namespace": "clanguml::t00021",
      "source_location": {
        "file": "../../tests/t00021/t00021.cc",
        "line": 22
      },
      "template_parameters": [],
      "type": "class"
    },
    {
      "bases": [
        {
          "access": "public",
          "id": "1668671110672744395",
          "is_virtual": false,
          "name": "clanguml::t00021::Visitor"
        }
      ],
      "display_name": "clanguml::t00021::Visitor3",
      "id": "1399026228179178025",
      "is_abstract": false,
      "is_nested": false,
      "is_struct": false,
      "is_template": false,
      "is_union": false,
      "members": [],
      "methods": [
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "visit_A",
          "parameters": [
            {
              "name": "item",
              "type": "const clanguml::t00021::A &"
            }
          ],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "visit_B",
          "parameters": [
            {
              "name": "item",
              "type": "const clanguml::t00021::B &"
            }
          ],
          "type": "void"
        }
      ],
      "name": "Visitor3",
      "namespace": "clanguml::t00021",
      "source_location": {
        "file": "../../tests/t00021/t00021.cc",
        "line": 28
      },
      "template_parameters": [],
      "type": "class"
    },
    {
      "bases": [],
      "display_name": "clanguml::t00021::Item",
      "id": "1491568826758947722",
      "is_abstract": true,
      "is_nested": false,
      "is_struct": false,
      "is_template": false,
      "is_union": false,
      "members": [],
      "methods": [
        {
          "access": "public",
          "is_const": false,
          "is_defaulted": true,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "~Item",
          "parameters": [],
          "type": "void"
        },
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": true,
          "is_static": false,
          "is_virtual": true,
          "name": "accept",
          "parameters": [
            {
              "name": "visitor",
              "type": "const clanguml::t00021::Visitor &"
            }
          ],
          "type": "void"
        }
      ],
      "name": "Item",
      "namespace": "clanguml::t00021",
      "source_location": {
        "file": "../../tests/t00021/t00021.cc",
        "line": 34
      },
      "template_parameters": [],
      "type": "class"
    },
    {
      "bases": [
        {
          "access": "public",
          "id": "1491568826758947722",
          "is_virtual": false,
          "name": "clanguml::t00021::Item"
        }
      ],
      "display_name": "clanguml::t00021::A",
      "id": "1494142745564026823",
      "is_abstract": false,
      "is_nested": false,
      "is_struct": false,
      "is_template": false,
      "is_union": false,
      "members": [],
      "methods": [
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "accept",
          "parameters": [
            {
              "name": "visitor",
              "type": "const clanguml::t00021::Visitor &"
            }
          ],
          "type": "void"
        }
      ],
      "name": "A",
      "namespace": "clanguml::t00021",
      "source_location": {
        "file": "../../tests/t00021/t00021.cc",
        "line": 40
      },
      "template_parameters": [],
      "type": "class"
    },
    {
      "bases": [
        {
          "access": "public",
          "id": "1491568826758947722",
          "is_virtual": false,
          "name": "clanguml::t00021::Item"
        }
      ],
      "display_name": "clanguml::t00021::B",
      "id": "1452948650450999568",
      "is_abstract": false,
      "is_nested": false,
      "is_struct": false,
      "is_template": false,
      "is_union": false,
      "members": [],
      "methods": [
        {
          "access": "public",
          "is_const": true,
          "is_defaulted": false,
          "is_implicit": false,
          "is_pure_virtual": false,
          "is_static": false,
          "is_virtual": true,
          "name": "accept",
          "parameters": [
            {
              "name": "visitor",
              "type": "const clanguml::t00021::Visitor &"
            }
          ],
          "type": "void"
        }
      ],
      "name": "B",
      "namespace": "clanguml::t00021",
      "source_location": {
        "file": "../../tests/t00021/t00021.cc",
        "line": 45
      },
      "template_parameters": [],
      "type": "class"
    }
  ],
  "metadata": {
    "clang_uml_version": "0.3.5-27-g81c7ce7",
    "llvm_version": "Ubuntu clang version 15.0.6",
    "schema_version": 1
  },
  "name": "t00021_class",
  "relationships": [
    {
      "access": "public",
      "destination": "1494142745564026823",
      "source": "1668671110672744395",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1452948650450999568",
      "source": "1668671110672744395",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1494142745564026823",
      "source": "1028369219400401946",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1452948650450999568",
      "source": "1028369219400401946",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1668671110672744395",
      "source": "1028369219400401946",
      "type": "extension"
    },
    {
      "access": "public",
      "destination": "1494142745564026823",
      "source": "1710373315476287130",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1452948650450999568",
      "source": "1710373315476287130",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1668671110672744395",
      "source": "1710373315476287130",
      "type": "extension"
    },
    {
      "access": "public",
      "destination": "1494142745564026823",
      "source": "1399026228179178025",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1452948650450999568",
      "source": "1399026228179178025",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1668671110672744395",
      "source": "1399026228179178025",
      "type": "extension"
    },
    {
      "access": "public",
      "destination": "1668671110672744395",
      "source": "1491568826758947722",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1668671110672744395",
      "source": "1494142745564026823",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1491568826758947722",
      "source": "1494142745564026823",
      "type": "extension"
    },
    {
      "access": "public",
      "destination": "1668671110672744395",
      "source": "1452948650450999568",
      "type": "dependency"
    },
    {
      "access": "public",
      "destination": "1491568826758947722",
      "source": "1452948650450999568",
      "type": "extension"
    }
  ],
  "using_namespace": "clanguml::t00021"
}
```
