0

So, I have created 2 interfaces One is called Observer and the other one Subject Observer contains update() method and Subject contains Boolean registerObserver(Observer o), Boolean removeObserver(Observer o) and void notifyObservers().

When I need to define the methods of Subject in a class I do not understand how should I use the ArrayList observers.

Thanks in advance for your help

Marged
  • 10,577
  • 10
  • 57
  • 99
P.Mit
  • 1
  • 4
    It's not clear what you're asking. If a subject has a collection of observers presumably when the subject does something "observable" then you'd notify all the observers. – Dave Newton Nov 06 '16 at 20:54
  • This sounds like you have an assignment to implement the `Subject` interface, and you were given the hint that you should use an `ArrayList` to do so. So in general, `registerObserver()` should *add* to your ArrayList, `removeObserver()` should *remove* from the ArrayList, and `notifyObservers()` should loop over the ArrayList and notify each observer therein. – Alex Wittig Nov 06 '16 at 20:59
  • It is actually a piece of code I was given to study and understand, but it is not pretty clear to me what : - an observer is (is it a class?) - a subject is (is it an object?) and why I need to hold the observers in an ArrayList Thank you for your response, I apologise if I am not clear. – P.Mit Nov 06 '16 at 21:31

0 Answers0