Meaning
Replace conditional logic with polymorphism to eliminate duplicated conditionals and improve maintainability.
Primary Function
Replace conditional logic with polymorphism.
Communicative Purpose
Communicate the intent to replace conditional logic with polymorphism.
Pattern
Replace conditional with polymorphism
Core Structure
Replace conditional statements that check object type with polymorphic method calls in subclasses.
Função primária
Replace conditional logic with polymorphism.
Propósito comunicativo
Communicate the intent to replace conditional logic with polymorphism.
Situações de gatilho
When you have a conditional that behaves differently based on object type and appears in multiple places.
Contextos
Object-oriented programming, refactoring, dealing with type-based conditionals.
Padrão
Replace conditional with polymorphism
Estrutura central
Replace conditional statements that check object type with polymorphic method calls in subclasses.
Slots de substituição
[conditional logic] -> [polymorphic method]
Colocados típicos
- conditional
- polymorphism
- refactoring
- subclass
- method
Substituições comuns
- Replace conditional with Strategy pattern
- Replace conditional with Visitor pattern
Erros comuns
Applying polymorphism when there are only two cases, Overusing polymorphism for simple conditionals
Similar / contraste
Replace Conditional with State Pattern, Replace Conditional with Strategy Pattern
Interferências
Overuse can lead to unnecessary class proliferation and increased complexity.
Família do chunk
- Refactoring patterns
- Polymorphism patterns
Nuance
Most effective when the conditional logic is based on object type and likely to expand with new types.
Efeito pragmático
Improves maintainability by eliminating duplicated conditional logic.
Dica de memória
Replace conditionals with polymorphism.
Nota
From Martin Fowler's Refactoring book.
Upgrade path
Replace Conditional with Strategy Pattern
Log in to save chunks.