#include <iostream>
// Abstract class acting as an interface
class Logger {
public:
virtual void logInfo(const std::string& message) = 0;
virtual void logWarning(const std::string& message) = 0;
virtual void logError(const std::string& message) = 0;
};
class ConsoleLogger : public Logger {
public:
void logInfo(const std::string& message) override {
std::cout << "INFO: " << message << std::endl;
}
void logWarning(const std::string& message) override {
std::cout << "WARNING: " << message << std::endl;
}
void logError(const std::string& message) override {
std::cout << "ERROR: " << message << std::endl;
}
};
class FileLogger : public Logger {
public:
void logInfo(const std::string& message) override {
// Imagine this writes to a file
std::cout << "Writing INFO to file: " << message << std::endl;
}
void logWarning(const std::string& message) override {
// Imagine this writes to a file
std::cout << "Writing WARNING to file: " << message << std::endl;
}
void logError(const std::string& message) override {
// Imagine this writes to a file
std::cout << "Writing ERROR to file: " << message << std::endl;
}
};
int main() {
ConsoleLogger consoleLogger;
FileLogger fileLogger;
consoleLogger.logInfo("Application started.");
fileLogger.logError("File not found.");
return 0;
}