Visitor Pattern
Learn Visitor Pattern (Behavioral Patterns, Design Patterns in Java) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
What is Visitor Pattern? Visitor Pattern lets you add new operations to a group of classes without modifying those classes themselves. Real-Life Example: • A Tax Auditor - visits different account types (Savings, Current) and applies different rules to each, without the account classes knowing anything about tax rules. • A Shopping Cart discount calculator - "visits" different item types (Book, Electronics) and applies different discount logic per type. Why do we need it? • Adding a new operation normally means modifying every element class to support it. • Visitor moves that operation's logic...