23T2 Week 10
Wednesday 1PM - 4PM (W13A)
Thursday 3PM - 6PM (H15B)
Slides by Alvin Cherk (z5311001)
Please fill it in (10 mins)
Problem: How do I add extra functionalities to subclasses without violating open/closed principle.
Problem: How do I add extra functionalities to subclasses without violating open/closed principle.
Behavioural Pattern
Computer.java
In this scenario we have Computers, Keyboards and Mouses which all are of type ComputerComponent
. We want to be able to 'visit' different types of Computer components by logging the following messages:
Looking at computer Corelli with memory 500 GB.
Looking at keyboard Mechanical keyboard which has 36 keys.
Looking at mouse Bluetooth mouse.
In particular though, anyone which is visiting a Computer
must be validated prior to being able to visit.
Extend/modify the starter code to use the Visitor Pattern to allow different computer components to be visited.