#include <cstdint>
#include <iostream>
/** Base class with virtual interface for initialization.
*
* Provides a stable interface for derived classes to override the initialization method.
* All derived classes must implement the init method with appropriate parameter types.
*/
class BaseInitializer {
public:
BaseInitializer() = default;
virtual ~BaseInitializer() = default;
/** Initialize with 32-bit integer parameter.
*
* @param value The integer value for initialization.
*/
virtual void init(int32_t value) noexcept {}
};
/** Derived class implementing integer-based initialization.
*
* Provides a concrete implementation of the initialization interface for integer values.
*/
class IntInitializer final : public BaseInitializer {
public:
IntInitializer() = default;
/** Initialize with 32-bit integer parameter.
*
* @param value The integer value for initialization.
*/
void init(int32_t value) noexcept override {
std::cout << "IntInitializer::init called with value: " << value << std::endl;
}
};
/** Another derived class implementing integer-based initialization.
*
* Provides an alternative concrete implementation of the initialization interface.
*/
class AltInitializer final : public BaseInitializer {
public:
AltInitializer() = default;
/** Initialize with 32-bit integer parameter.
*
* @param value The integer value for initialization.
*/
void init(int32_t value) noexcept override {
std::cout << "AltInitializer::init called with value: " << value << std::endl;
}
};
/** Derived class supporting overloaded initialization methods.
*
* Provides initialization with both integer and string parameters, demonstrating
* method overloading in a class hierarchy.
*/
class MultiInitializer final : public BaseInitializer {
public:
MultiInitializer() = default;
/** Initialize with 32-bit integer parameter.
*
* @param value The integer value for initialization.
*/
void init(int32_t value) noexcept override {
std::cout << "MultiInitializer::init(int32_t) called with value: " << value << std::endl;
}
/** Initialize with string parameter.
*
* @param text The string value for initialization.
*/
void init(const char * text) noexcept {
std::cout << "MultiInitializer::init(const char*) called with text: " << text << std::endl;
}
};
int32_t main() noexcept {
std::cout << "=== Starting initialization demonstration ===" << std::endl;
IntInitializer initializer1;
std::cout << "Created IntInitializer" << std::endl;
initializer1.init(10);
AltInitializer initializer2;
std::cout << "Created AltInitializer" << std::endl;
initializer2.init(10);
MultiInitializer initializer3;
std::cout << "Created MultiInitializer" << std::endl;
initializer3.init(10);
initializer3.init("a");
std::cout << "=== Initialization demonstration completed ===" << std::endl;
return 0;
}