public interface IModel
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(IModelEventListener listener)
Add event listener.
|
java.lang.String |
generateModelData()
Return the string (in a specific format, normally json) that contains
all the necessary data to describe the model
|
IModelData |
getModelData()
Model data might be scattered into fields of the model object.
|
IModelData |
getModelData(IModelData data)
In many cases, we have a model inherit from another model, hence the model data should also include the data of the parent class.
|
java.lang.Class<?> |
getModelDataClass()
Return the class that represent the data of this model.
|
long |
getModelId() |
java.lang.String |
getModelName()
Get the display name of the model
|
float |
getRunningProgress()
Get model progress.
|
void |
initialize()
Since we want to load model dynamically, the constructor is not having any argument
Instead, parameters needed for initialization will be set via get set function
And then the initialize function will be called.
|
void |
readModelData(java.lang.String modelData)
Given a string contains the model data, this function will load this data
into the current model
|
void |
removeEventListener(IModelEventListener listener)
Remove event listener
|
void |
start()
Start function is called when the model start running.
|
void |
stop()
TO BE ADDED LATER
public CompletionStage
|
void start()
void stop()
void initialize()
java.lang.String getModelName()
long getModelId()
java.lang.String generateModelData()
void readModelData(java.lang.String modelData)
modelData - IModelData getModelData()
IModelData getModelData(IModelData data)
In many cases, we have a model inherit from another model, hence the model data should also include the data of the parent class.
To do this, we can make the model data of the child class inherit the model data of the parent class.
When this function is invoked in the child class, it first create an empty model data, and ask the parent class to fill in the necessary details, then it will fill in its data later. Doing this, will lessen the amount of work the child class need to do and avoid duplicate code (i.e. implement the same code to fill in the same data in both child and parent class).
Implementation of this class should have the form
if (data == null) return getModelData();
if (ChildDataObject.class.isAssignableFrom(data.getClass())) {
ChildDataObject d = (ChildDataObject)data;
// if there is parent class for this class,
d = (ChildDataObject)super.getModelData(d)
// fill in the necessary data
return d;
} else {
throw new NotCompatibleModelDataClassException("The model data passed in to "+this.getClass().getName()+" is not a descendant of "+ChildDataObject.class.getName()+" and so, is not compatible.");
}
where super.getModelData will fill in the details of the parent class to the data object. The ChildDataObject class should be
a descendant of the ParentDataObject class.
dataObject - : the data object that needs to be filled injava.lang.Class<?> getModelDataClass()
float getRunningProgress()
void addEventListener(IModelEventListener listener)
void removeEventListener(IModelEventListener listener)