AntiPattern Flashcards
Anemic Domain Model
Refers to a design flaw in OOP where domain objects(objects repsrenting real-world concepts or entities) lack behavior or business logic and serve primarily as data containers.
In an Anemic DOmain Model, most of the behavior and business logic is implemented in separate service or utility classes rathern than encapsulated with the domain objects themselves
Spaghetti Code
Is characterized by tangled and poorly stuctutured logic, often resulting from ad-hoc development w/o proper planning or design. It leads to convoluted control flow, making the code difficult to read, debug, and maintain.
Anemic Domain Model Solution
Domain objects should encapsulate both data and behavior related to a specific domain concept, allowing them to enforce business rules and invariants internally. By focusing on rich domain models that encapsulate behavior, developers can create more expressive, maintainable, and reusable codebases that accurately represent the complexities of the domain they are modeling.
Spaghetti Code Solution
Apply modular design principles and refactor the codebase to break it into smaller, more manageable modulesor components. Adopt design patterns such as MVC (Model-View-Controller) or MVP (Model-View-Presenter) to organize the code and separate concerns effectively.
Copy-Paste Programming
Involves duplicating code instead of abstracting common fuctionaloty into reusable components.
It leads to code, redundancy, inconsistency, and increased maintenance overhead
Copy-Paste Programming Solution
Identify duplicated code and refactor it into reusable functions, methods, or classes. Encourage code reuse by extracting common functionality into libraries or shared components. Maintain a codebase that adheres to the DRY (Don’t Repeat Yourself) principle
Magic Numbers
Magic Numbers are hard-coded numerical values scattered throughout the codebase w/o explanation. They lack clarity and make the code difficult to understand and maintain.
Magic Numbers Solution
Replace magic numbers with named constants or configuration parameters to improve code readability and maintainability. Use descriptive names for constants that convey their purpose and context within the code
Constant Interface
The Constant Interface Antipattern is a design flaw in object-oriented programming where an interface is used solely to declare a set of constant variables instead of using a class to define constants. Interfaces in Java are meant to declare a contract for behavior, not for defining constants.
Using interfaces for constants misuses their intended purpose and can confuse developers who expect interfaces to define behavior.
Constant Interface Solution
One commonly recommended solution is to use a “static” class with a private constructor to encapsulate the constants. Another approach is to leverage enums for defining constants, especially when the constants represent a finite set of related values. By adopting these solutions, developers can mitigate the issues associated with the Constant Interface Antipattern and create more maintainable and readable codebases that adhere to best practices in object- oriented design
Dead Code
Refers to unreferenced or unreachable portions of the database that no longer serve a purpose. It clutters the database, increases its size, and can confuse the developer
Dead Code Solution
Conduct regular code reviews and static code analysis to identify and remove dead code. Utilize version control systems to track changes and detect unused code. Ensure that developers are aware of the importance of maintaining a clean codebase
Feature Creep
Occurs when new features are continuously added to a software project w/o proper prioritization or consideration of their impact.
It leads to bloated software w. Unnecessary complexity, longer development cycles, and increased maintenance costs.
Feature Creep Solution
Conduct regular code reviews and static code analysis to identify and remove dead code. Utilize version control systems to track changes and detect unused code. Ensure that developers are aware of the importance of maintaining a clean codebase
Golden Hammer
Occurs when developers over-rely on a familiar or preferred technology or tool for solving every problem, regardless of its suitability. It can lead to suboptimal solutions, missed opportunities, and resistance to adopting better alternatives.
Golden Hammer Solution
Encourage a diverse toolkit and evaluate technologies based on their suitability for the problem at hand.Foster a culture of learning and experimentation to explore new technologies and approaches. Conduct regular technology evaluations and be open to adopting better alternatives
Circular Dependency
Arises when 2 or more modules or components depend on each other directly or indirectly.
It creates tight coupling b/w components, making the codebase difficult to understand, test, and maintain.
Circular Dependency Solution
Break circular dependencies by refactoring the codebase to introduce interfaces or abstract dependencies. Utilize dependency injection or inversion of control to decouple modules and promote modularity. Establish clear architectural guidelines to prevent the emergence of circular dependencies.
Big Ball of Mud
Is a Large, sprawling and unstructured codebase lacking clear architecture or design.
It accumulates technical debt and complexity over time w/o proper planning or refactoring.
Big Ball of Mud Solution
Introduce architectural patterns such as layered architecture or microservices to promote modular design and separation of concerns. Refactor the codebase incrementally, focusing on extracting cohesive modules and enforcing architectural boundaries.