开发者

How to prepare Business Objects for possible expansion in web services

While creating a Web service I decided to exchange Busi开发者_如何学Pythonness Object (BO) between client and web service.

If in the future I get a request to expand my model and put some new attributes (field) in my BO and send it to the client, what would be the best approach?

So basically, each BO may have 0..n meta-fields.

Each meta-field is Key,Value like, where keys can be anything from simple data types to other BOs.

Here is a little Java code for modelling BOs, I just need confirmation that I'm on the right track.

class AbstractBO{

 //optional list of meta fields for future extension
 List<MetaField> metaFieldList;

 //setters. getters

}

----

class MetaField {

 private Object key;
 private Object value; 

// setters
// getters

}

----

class MyBO extends AbstractBO {

//BO specific fields
private String name;
...


}

---

TODAY

class Person extends AbstractBO {

 private String name;
 private int age;

 //extend metaFieldList = null;

}


----

TOMORROW

class Person extends AbstractBO {

 private String name;
 private int age;

 //list with new metafield 

}

How to model Person for Tomorrow purposes?


If, as your follow-up comment implies, you actually want to send the direct object code (presumably by implementing Serializable) instead of using a XML or JSON (which is what you'd typically do when implementing a web service), then I don't know how you'd actually be able to achieve what you want.

When Java tries to recreate your object by deserializing it, it will have to match the input data against what it believes the class to be. For best practice purposes, you should be implementing serialVersionUID and changing it each time you modify your class so that when you add variables, the person on the other end won't be able to erroneously reconstruct the class that you send them if they have an old version of the code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜