MVC and OOD
hi there.
I am currently working on a college project and it should be using OO Design, I got a problem to design a class diagram and not sure how to apply MVC on this API project.
what i got so far is.
Data classes - this is a set of data classes.
1) DataSetGroup
2) DataSet
3) DataIn
API classes - API is divided up into model and GUI
1) GrahpModel - it extends DataSetGroup class. it encapsulates a set of data is used to construct a GraphUI.
I have read the MVC meets Swing on Java.Sun site, model class should extends "Obervalbe class"? which mean my GraphModel should extend Obervable clasee? but it extends a class already...... pls help.
2) GraphUI - this display the information graphically.
I need to display a bar graph and pie chart base on the GrahpModel's data. so what classes should i create for them? just BarGraph and PieChart classes? and where should i place them? should they extend observer class?
Pls give me some directions and suggestions.
Thanks in advance.
Have your bar graph and pie chart (view) classes subclass from an abstract class called AbstractDataView that contains the following methods:
// update display with new data
protected abstract void updateDisplay();
// receive data updates/changes from your data class
public void update( Observable observable, Object object )
{
updateDisplay();
}
Also add a data reference to AbstractDataView that:
// registers as an Observer to receive data updates/changes
data.addObserver( this );
The bar graph and pie chart view classes thus need to define the update() method (from AbstractDataView) and also register respectively via data.addObserver(this)
//************************************************************
//************************************************************
Then, whenever your user interface (controller class) directs a change have it invoke this callBack method located in your data class:
// set Account balance and notify observers (views) of change
private void callBack( double someData )
{
// must call setChanged before notifyObservers to
// indicate model has changed
setChanged();
// notify Observers that model has changed
notifyObservers();
}