Week 10
TUESDAY 9AM - 12PM (T09B)
TUESDAY 1PM - 4PM (T13B)
WEDNESDAY 6PM - 9PM (W18A)
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.