Sobes.tech
Junior — Middle

What design patterns do you apply in your work?

sobes.tech AI

Answer from AI

In my work with C/C++, I often use the following design patterns:

  • Singleton — to ensure a single instance of a class, for example, for a configuration manager.
  • Factory Method — to create objects without specifying the exact class, which simplifies extending functionality.
  • Observer — to implement event subscription, for example, in feedback systems.
  • RAII (Resource Acquisition Is Initialization) — although it's more of an idiom, it helps manage resources through constructors and destructors.

Example of Singleton in C++:

class Logger {
public:
    static Logger& getInstance() {
        static Logger instance;
        return instance;
    }
    void log(const std::string& message) {
        // logging
    }
private:
    Logger() {}
    Logger(const Logger&) = delete;
    void operator=(const Logger&) = delete;
};