SECTION 06 / 6

Choose the right solution

1 min read

When choosing a design approach, first identify the problem described in the sections: overall system organization (architecture), class responsibilities and dependencies (SOLID), object creation (creational patterns), interface compatibility or subsystem simplification (structural patterns), or object communication and algorithm selection (behavioral patterns). The comparison below summarizes these distinctions.

SituationLikely conceptWhy
Search site receives browser requestsClient–serverRequest and response
Compiler processes code in stagesPipe-and-filterSequential transformations
UI should not contain data rulesMVCSeparate view, model and control
Large Seller class mixes unrelated tasksSRPSeparate responsibilities
New product category changes Product every timeOCPExtend rather than edit stable core
SMSNotification cannot use notify(…, email)LSPPreserve substitution behavior
E-book order forced to implement packageOrder() and deliver()ISPAvoid irrelevant interface methods
Seller code creates BankAccount directlyDIPDepend on PaymentAccount
Choose a courier implementationFactory MethodSelect a concrete product
Create Book with many optional fieldsBuilderStepwise construction
Order placement requires four service callsFacadeOne simple entry point
Product cannot call ConversionCalculator directlyAdapterTranslate incompatible contracts
Traverse many booksIteratorHide collection representation
Notify subscribed buyersObserverPublish updates
Choose FIFO or priority processingStrategySwap algorithms
YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑