# t00020 - Abstract factory pattern
## Config
```yaml
compilation_database_dir: ..
output_directory: puml
diagrams:
  t00020_class:
    type: class
    glob:
      - ../../tests/t00020/t00020.cc
    using_namespace:
      - clanguml::t00020
    include:
      namespaces:
        - clanguml::t00020
    plantuml:
      after:
        - '@A(ProductA1) <.. @A(Factory1)'
        - '@A(ProductB1) <.. @A(Factory1)'
        - '{{ alias("ProductA2") }} <.. {{ alias("Factory2") }}'
        - '{{ alias("ProductB2") }} <.. {{ alias("Factory2") }}'

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

namespace clanguml {
namespace t00020 {

class ProductA {
public:
    virtual ~ProductA() = default;
    virtual bool sell(int price) const = 0;
};

class ProductA1 : public ProductA {
public:
    bool sell(int price) const override { return price > 1000; }
};

class ProductA2 : public ProductA {
public:
    bool sell(int price) const override { return price > 2000; }
};

class ProductB {
public:
    virtual ~ProductB() = default;
    virtual bool buy(int price) const = 0;
};

class ProductB1 : public ProductB {
public:
    bool buy(int price) const override { return price < 1000; }
};

class ProductB2 : public ProductB {
public:
    bool buy(int price) const override { return price < 2000; }
};

class AbstractFactory {
public:
    virtual std::unique_ptr<ProductA> make_a() const = 0;
    virtual std::unique_ptr<ProductB> make_b() const = 0;
};

class Factory1 : public AbstractFactory {
public:
    std::unique_ptr<ProductA> make_a() const override
    {
        return std::make_unique<ProductA1>();
    }

    std::unique_ptr<ProductB> make_b() const override
    {
        return std::make_unique<ProductB1>();
    }
};

class Factory2 : public AbstractFactory {
public:
    std::unique_ptr<ProductA> make_a() const override
    {
        return std::make_unique<ProductA2>();
    }

    std::unique_ptr<ProductB> make_b() const override
    {
        return std::make_unique<ProductB2>();
    }
};
}
}

```
## Generated UML diagrams
![t00020_class](./t00020_class.svg "Abstract factory pattern")
