How to face observable object containing an observable field

Posted by iseek on Stack Overflow See other posts from Stack Overflow or by iseek
Published on 2010-06-08T10:54:59Z Indexed on 2010/06/08 11:12 UTC
Read the original article Hit count: 215

Filed under:
|
|
|

Hello, I need a hint concerning MVC and Observer-Pattern.

For example a model contains the classes "Address" and "Person". The Address class contains the fields street:String, zipcode:String, location:String. Whereas the Person class contains the fields name:String, firstName:String, address:Address.

My approach so far looks something like this: Both, Address and Person are observable. If one of their setters is being called, I validate whether the current value and new value differ. Only in this case an update event is fired. The event contains the source, the name of the changed field, the old and the new value.

The class for the view contains text fields to display and edit the information of a person: name, firstname, street, zipcode, location. It knows the Person model and is an subscribed observer for the person. So it gets the update events from the person object.

My questions concerns the address field from type Address in the person class, since an address is observable on its own. If the view gets an update event from person when a new address has been set, I can update all of the address related fields in the view. But what if a field of the address changes? Should the view also register for update events from the address?

Any hints about common design approaches would be appreciated. Greetings.

© Stack Overflow or respective owner

Related posts about java

Related posts about mvc