Explain the Visitor, Strategy, and Observer patterns with use cases.
Answer
Visitor: separate algorithm from object structure. Elements accept visitors that perform operations. Use: compilers (AST operations), report generation. Avoids modifying element classes. Strategy: define family of interchangeable algorithms. Context holds strategy reference, delegates execution. Use: payment processing, sorting strategies, validation rules. Runtime algorithm selection. Observer: one-to-many dependency; subjects notify observers of state changes. Use: event systems, MVC, reactive programming. Decouples subjects from observers. All three follow Open/Closed principle - add new behavior without modifying existing classes.
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.