Inversion of Control

What is Inversion of Control (IoC)? Inversion of Control is a design principle in which the control of object creation and dependency management is transferred from the program to a framework or container. Instead of the class controlling its dependencies, an external entity provides them. This is commonly used to achieve loose coupling. There…

0 Comments

Event-Driven Pattern

The event-driven pattern (also called event-driven architecture, or EDA) is a software design pattern where components communicate and respond to each other through events rather than direct calls. Instead of one component explicitly invoking methods on another, it emits an event (a signal that something happened), and other components that are interested in that…

0 Comments

Hexagonal Architecture

1. What is Hexagonal Architecture? Hexagonal Architecture is a design pattern that emphasizes separation of concerns between: Core business logic (the domain) External systems (like databases, web frameworks, APIs, messaging) It achieves this by introducing: Ports: Interfaces that define what the application can do (input/output) Adapters: Implementations of these interfaces to communicate with external…

0 Comments

Dependency Injection

What is Dependency Injection? Dependency Injection is a design pattern used to implement Inversion of Control (IoC). Instead of a class creating its own dependencies, they are injected from outside. This makes code more flexible, testable, and maintainable. Dependency: An object that another object needs to function. Injection: The act of providing the dependency…

0 Comments

CQRS in Java

What is CQRS? CQRS is a pattern in software architecture that separates: Commands → operations that change state (Create, Update, Delete) Queries → operations that read state (Get, List, Search) The main idea: read and write operations are handled separately, allowing each to be optimized independently. Benefits: Scalability (reads/writes can scale separately) Clear separation…

0 Comments

Domain-Driven Design

1. DDD Layers Presentation Layer -> REST Controller / UI Application Layer -> Services coordinating use cases Domain Layer -> Business logic (Entities, Value Objects, Aggregates, Domain Services) Infrastructure Layer -> Database, Repositories Presentation Layer -> REST Controller / UI Application Layer -> Services coordinating use cases Domain Layer -> Business logic (Entities, Value…

0 Comments

JUnit

JUnit is a popular testing framework in Java used to write and run unit tests. It helps you test individual units (like methods) of your code to ensure they work as expected. Here’s a simple example using JUnit 5 (latest version): 1. Add JUnit dependency If you’re using Maven, add this to your pom.xml:…

0 Comments

Assertion in Java

In Java, assertions are a way to test assumptions about your program during runtime. They are primarily used for debugging purposes and help catch programming errors early. An assertion evaluates a boolean expression, and if the expression evaluates to false, the JVM throws an AssertionError. Syntax assert condition; assert condition; or assert condition :…

0 Comments

KISS in Java

The KISS principle says: write the simplest code that solves the problem without unnecessary complexity. 🚨 Without KISS (Over-Engineered Example) public class DiscountCalculator { // Overcomplicated discount logic public double calculateDiscount(double price, String customerType) { if (customerType.equals("REGULAR")) { if (price > 100) { return price * 0.9; } else { return price * 0.95;…

0 Comments

YAGNI in Java

In Java, this often happens when developers add extra classes, methods, or features “just in case.” 🚨 Without YAGNI (Over-engineering) public class ReportGenerator { // Feature not needed right now, but added "just in case" public String generatePDFReport(String data) { // Pretend to generate PDF (not needed yet) return "PDF Report: " + data;…

0 Comments

End of content

No more pages to load