Loading the lesson...
In the print dialog, choose "Save as PDF" as the destination.
Common Traps When Applying Design Patterns
Anti-Patterns
Misuse of Patterns
Golden Hammer, Pattern Obsession, Copy-Paste Programming
Architectural Anti-Patterns
Big Ball of Mud, Spaghetti Code, God Object
Code-Level Anti-Patterns
Magic Numbers, Dead Code, Duplicate Code
Singleton Abuse
Config, Database, Log managersSingleton Abuse
class OrderService:
def __init__(self, config, db, logger):
self.config = config
self.db = db
self.logger = logger
def process_order(self, order):
# use injected dependencies
passGod Factory
if/elif chains for each combination100+ lines of creation logic crammed into one classGod Factory
class UserFactory:
def create_admin(self, level): pass
def create_regular_user(self): pass
class ProductFactory:
def create_physical_product(self): pass
def create_digital_product(self): passprocessUser, handlePayment, sendEmail, validateData, generateReport, and dozens more methods.0.15 or code == 1 scattered through logicPREMIUM_RATE = 0.15Class over 500 lines?
yes: possible God Object
Method over 50 lines?
yes: extract methods
Duplicate code?
yes: apply the DRY principle
Magic numbers?
yes: extract named constants
Tight coupling?
yes: apply SOLID principles
Mahmoud Abas|Anti-Patterns: What NOT to Do