OOP2

AbstractView.java

1
import java.util.Observable;
2
import java.util.Observer;
3
4
/**
5
 * AbstractView - An abstraction layer for a view class in an MVC architecture.
6
 * @author Maarten Vangeneugden - 1438256
7
 */
8
abstract class AbstractView implements Observer {
9
10
	// Members
11
	private Observable model;
12
	private Controller controller;
13
14
	// Constructor
15
	public AbstractView(Observable model, Controller controller) { 
16
		setModel(model);
17
		setController(controller);
18
	}
19
20
	/**
21
	 * Sets the model associated with this view.
22
	 * @param model The model associated with this view.
23
	 */
24
	public void setModel(Observable model) {
25
		this.model = model;
26
	}
27
28
	/**
29
	 * Returns the model associated with this view.
30
	 * @return The model associated with this view.
31
	 */
32
	public Observable getModel() {	
33
		return model;
34
	}
35
36
	/**
37
	 * Sets the controller associated with this view.
38
	 * @param controller The controller associated with this view.
39
	 */
40
	public void setController(Controller controller) {
41
		this.controller = controller;
42
	}
43
44
	/**
45
	 * Returns the controller associated with this view.
46
	 * @return The controller associated with this view.
47
	 */
48
	public Controller getController() {	
49
		return controller;
50
	}
51
52
	/**
53
	 * This is an abstract method, in that it must be overridden in order to use this class. The method itself is an override of Observer.update().
54
	 * Please note that this function is not supposed to be called because that's something you can do with functions (methods, whatevs); This function is automatically triggered by the Observable class whenever its state is modified. So what is supposed to happen here, is that the subclass of this class takes the trigger class, and asks about its state to update his own stuff.
55
	 * @see Observable.update
56
	 * @param observable The class that is being observed. This is also the class that triggers this function. It's the observed class screaming it had an update, if you will. It literally sends itself as a parameter.
57
	 * @param information An Object containing additional information. This can be any class, so it's up to the subclass to deal with this, or not to deal with it at all.
58
	 * @post The View is updated so that it is a correct representation of its associated Model.
59
	 */
60
	@Override
61
	public abstract void update(Observable observable, Object information);
62
}
63