COMP2511

24T1 Week 10

Tuesday 6PM - 9PM (T18A)

 

Slides by Alvin Cherk (z5311001)

Admin

  • If you did assignment-iii, please make sure you submit it following the instructions in the spec.
    • No autogenerated UMLs
    • No ChatGPT blogs pls
    • Include video that is public. We will not be chasing this up since marking will happen during week 11/12

MyExperience

Please fill it in (10 mins)

Visitor Pattern

Visitor Pattern

Problem: How do I add extra functionalities to subclasses without violating open/closed principle.

Visitor Pattern

Problem: How do I add extra functionalities to subclasses without violating open/closed principle.

Visitor Pattern

Behavioural Pattern

  • Adds extra functionality to class without modifying the original (abides by open closed principle)
  • One class/interface (visitor) defines a computation/operation and another (visitable) is responsible for providing data access

Kahoot

Exam Tips

Exam Tips

  • Practice good exam techniques.
  • Get familiar with writing Java & Generics
  • Learn the patterns and the differences (YouTube has some really good resources if you don't understand certain ones).
  • Know code smells and methods of refactoring
     
  • Please ensure that your code compiles. Even if you didn't finish the question, at least get it to a compliable state (Write all the placeholder code you need to, to achieve this)
  • Please ensure that you get familiar with VSCode.
  • Open VSCode in the correct folder (for syntax support)
  • Don't waste all your time on 10% of the exam
  • You can use dot points if you're short on time or prefer to

Code Demo

Computer.java

Code Demo

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.

COMP2511 Week 10 24T1

By kuroson

COMP2511 Week 10 24T1

  • 124