PDA

View Full Version : Appropriate Usage of BaseModel vs BaseModelData



jpnet
3 Sep 2008, 8:52 PM
When is it appropriate to use BaseModel vs BaseModelData? Currently, I have a class subclassing BaseModel. However, I don't really understand why classes XmlReader/JsonReader and their associated methods rely on BaseModelData and not BaseModel.

Also, how does ModelType fit into all of this? Or more importantly, why is it necessary to have ModelType? Isn't that sort of like meta-metadata? Why can't the functionality of ModelType be bundled into BaseModel or BaseModelData?

Thanks in advance for any help advice.

-JP

jpnet
4 Sep 2008, 10:00 AM
Can any experts chime in?

Thanks,

JP

gslender
4 Sep 2008, 1:31 PM
1st, not an expert but happy to provide comments...

When is it appropriate to use BaseModel vs BaseModelData?
Depends on your needs - BaseModelData contains extra methods for events etc


Currently, I have a class subclassing BaseModel. However, I don't really understand why classes XmlReader/JsonReader and their associated methods rely on BaseModelData and not BaseModel.

They need events


Also, how does ModelType fit into all of this? Or more importantly, why is it necessary to have ModelType? Isn't that sort of like meta-metadata? Why can't the functionality of ModelType be bundled into BaseModel or BaseModelData?

ModelType is used to describe the elements root and total. That functionality could probably be extracted out of reusing modeldata, but how confusing would that then be considering it returns a list of modeldatas... /:)

jpnet
4 Sep 2008, 1:42 PM
Most of what you said is fairly clear. However, I'm still not sure why XmlReader and JsonReader require me to call "addField" on my ModelTypes. For example, for every class that I have that is subclassing BaseModel, I have a method implemented in that class called "getModelType" implemented as such:



public static ModelType getModelType()
{
ModelType mt = new ModelType();
mt.id = "id"; mt.root = "lamp_sessions"; mt.totalName = "total"; mt.recordName = "lamp_session";
mt.addField("output_um", "output_um");
mt.addField("install_date", "install_date");
return mt;
}


Obviously, I have to call addField for every field in the class. It get's to be a bit tedious. Maybe, I'm doing something wrong... but the whole design of BaseModelData, ModelData, and ModelType seem to be a bit redundant. But then again, I'm still a noob with GXT and I come from the C# world.

Thanks again for taking the time to respond, you seem to be one of the few that routinely responds, and your responses are sincerely appreciated.

-JP

gslender
4 Sep 2008, 5:44 PM
well don't use XML or JSON - use RPC and then you get to use BeanModel which means your pojo just works as is...

if you have to use JSON/XML, all you MUST do is convert to ModelData

the ModelType/Reader/Loader convenience classes designed to help load them are just that, convenience classes - if you think a better design that suits your need exists then just create it and convert to ModelData

jpnet
5 Sep 2008, 7:11 AM
I would love to use RPC, except for the fact that I'm not using Java on the server side. So, it's my understanding that I'm stuck with JSON/XML.

-JP