Design Patterns Handbook
  • Introduction
  • Creational Patterns
    • Builder
    • Factory
    • Abstract Factory
    • Factory Method
    • Prototype
    • Singleton
    • Object Pool
    • Revealing Constructor
  • Structural Patterns
    • Adapter
    • Composite
    • Proxy
    • Flyweight
    • Facade
    • Bridge
    • Decorator
    • Private Class Data
  • Behavioral Patterns
    • Template Method
    • Mediator
    • Chain Of Responsibility
    • Observer
    • Strategy
    • Command
    • State
    • Visitor
    • Memento
    • Interpreter
    • Null Object
    • Iterator
    • Middleware
  • Clean Code Patterns
    • Extract Method
    • Clarify Responsibility
    • Remove Duplications
    • Keep Refactoring
    • Always Unit Test
    • Create Data Type
    • Comment to Better Name
    • Consistent Naming
    • If-else over ternary operator
    • Composition over Inheritance
    • Too Many Returns
    • Private to Interface
  • Anti Patterns
    • Big Ball of Mud
    • Singleton
    • Mad Scientist
    • Spaghetti Code
    • It Will Never Happen
    • Error Codes
    • Commented Code
    • Abbreviations
    • Prefixes
    • Over Patternized
    • Generic Interface over Function
Powered by GitBook
On this page

Was this helpful?

  1. Anti Patterns

Spaghetti Code

PreviousMad ScientistNextIt Will Never Happen

Last updated 5 years ago

Was this helpful?

We have spaghetti code in the project when the flow is conceptually like a bowl of spaghetti, i.e. twisted and tangled. There are other as well.

Example

With spaghetti code, we never know where the code starts and where the code ends.

class DefaultModule {
    public static Processor proc() {
        return new Processor();
    }
}

class IQModule {
    public Processor process() {
        Processor proc = DefaultModule.proc();
        return proc;
    }
}

class Processor {
    public void exec() {
        Processor process = new IQModule().process();
        process.exec();
    }
}
Italian type of code