Member-only story

Java : Common Anti Patterns to Avoid

Skilled Coder
7 min readDec 25, 2024

An anti-pattern is a commonly used but ineffective or counterproductive solution to a recurring software development problem. In other words, while design patterns guide you toward good practices, anti-patterns highlight what you should avoid. They often stem from short-term hacks, poor design decisions, or an overuse/misuse of particular features of a language or framework.

The God Class (a.k.a. Blob or Monster Object)

A God Class is a single class that tries to handle too many responsibilities at once , business logic, data manipulation, UI interactions, database operations etc. This violates the Single Responsibility Principle (SRP) and leads to a monolithic class that’s difficult to test, maintain, and extend.

public class GodClass {
private List<String> dataList = new ArrayList<>();

// Business logic
public void processData() {
// ...some complex data processing
System.out.println("Processing data...");
}

// Database interactions
public void saveDataToDb() {
// ...code to save dataList to the database
System.out.println("Data saved to DB.");
}

// UI or console logic
public void displayData() {
// ...code to display data
System.out.println("Displaying data...");
}

// Another random method
public…

--

--

Skilled Coder
Skilled Coder

Written by Skilled Coder

Sharing content and inspiration on programming. Coding Newsletter : https://skilledcoder.substack.com

Responses (4)