Skip to content

YuriiJavaDev/JavaBasics_Task_360_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event Logging System: Strategy Pattern (JavaBasics_Task_360_V0.1)

📖 Description

In mission-critical applications, the ability to switch output destinations without altering core logic is vital. This project implements a Flexible Logging System using interface-based polymorphism. By defining a universal Logger contract, the system can treat ConsoleLogger and FileLogger as interchangeable components. This architectural approach follows the Dependency Inversion Principle, where high-level modules depend on abstractions (interfaces) rather than concrete implementations.

📋 Requirements Compliance

  • Unified Contract: Established the Logger interface with a mandatory log(String message) method.
  • Behavioral Diversity: Developed ConsoleLogger for immediate debugging and FileLogger to simulate persistent storage.
  • Interchangeability: Demonstrated the ability to call the same method signature on different object types via an interface reference.
  • System Flexibility: Proven that new logging destinations (e.g., DatabaseLogger) can be added without modifying existing client code.

🚀 Architectural Stack

  • Java 8+ (Interfaces, Polymorphism, Decoupling)

🏗️ Implementation Details

  • Logger: The core interface defining the event reporting protocol.
  • ConsoleLogger: Direct standard output implementation.
  • FileLogger: Simulated file-system output implementation.
  • LogLauncherApp: The test harness demonstrating behavioral switching.

📋 Expected result

Test message
Log written to file: Test message

💻 Code Example

Project Structure:

JavaBasics_Task_360/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── app/
│                 │   └── LogLauncherApp.java
│                 └── logging/
│                     ├── contracts/
│                     │   └── Logger.java
│                     └── modules/
│                         ├── ConsoleLogger.java
│                         └── FileLogger.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md

Code

package com.yurii.pavlenko.app;

import com.yurii.pavlenko.logging.contracts.Logger;
import com.yurii.pavlenko.logging.modules.ConsoleLogger;
import com.yurii.pavlenko.logging.modules.FileLogger;

public class LogLauncherApp {

    public static void main(String[] args) {

        Logger consoleLogger = new ConsoleLogger();
        Logger fileLogger = new FileLogger();

        String testMessage = "Test message";

        consoleLogger.log(testMessage);
        fileLogger.log(testMessage);
    }
}
package com.yurii.pavlenko.logging.contracts;

public interface Logger {
    void log(String message);
}
package com.yurii.pavlenko.logging.modules;

import com.yurii.pavlenko.logging.contracts.Logger;

public class ConsoleLogger implements Logger {
    @Override
    public void log(String message) {
        System.out.println(message);
    }
}
package com.yurii.pavlenko.logging.modules;

import com.yurii.pavlenko.logging.contracts.Logger;

public class FileLogger implements Logger {
    @Override
    public void log(String message) {
        System.out.println("Log written to file: " + message);
    }
}

⚖️ License

This project is licensed under the MIT License.

Copyright (c) 2026 Yurii Pavlenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...

License: MIT

About

This is a tutorial project. JavaBasics_Task_360_V0.1 Logging System: implementing interchangeable logging strategies through the Logger interface for console and file-simulated outputs. 260426_1027

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages