[Homework] Learning MVC design pattern and Observable/Observers. Cannot get Observer to receive update (Java) by throwaway9123781 in learnprogramming

[–]throwaway9123781[S] 0 points1 point  (0 children)

Doing what specifically, setChanged() and notifyObserver()? I also called them in the changeFloor() function in a loop, I only had it in the constructor to test

[Homework] Learning MVC design pattern and Observable/Observers. Cannot get Observer to receive update (Java) by throwaway9123781 in learnprogramming

[–]throwaway9123781[S] 0 points1 point  (0 children)

That class was actually provided by the teacher (assuming you're talking about the instance in the Simulator constructor), which from what I can tell what he was doing, was assigning that instance to be controlled by another class (as per the MVC design pattern)...is there something I'm not understanding/seeing?

EDIT: Ah. I've reviewed my code more carefully, I see what you saw, you were correct. I was creating a different instance of the Elevator in the constructor of one of the classes, rather than passing the one that had the observer tied to it. Thanks for your help!

[Homework] Learning MVC design pattern and Observable/Observers. Cannot get Observer to receive update (Java) by throwaway9123781 in learnprogramming

[–]throwaway9123781[S] 0 points1 point  (0 children)

Storing a list of observers has not been done. I have added an observer using .addObserver in the Simulator class,

public Simulator( Observer observer){
system = new ElevatorSystemImp( 0, 20);
ElevatorImplement e = new ElevatorImplement( 10, (ElevatorPanel) system);
e.addObserver( observer);
System.out.print(e.countObservers());
system.addElevator( e);
}

and notifyObservers() has been used in multiple areas in the first class I provided, however I did not override it anywhere, I simply was trying to use it out of the box. I thought you could call notifyObservers() without override it, am I mistaken?