Observer Design Pattern in Java

60 views
Skip to first unread message

mjash

unread,
Jun 5, 2013, 10:39:06 AM6/5/13
to vog...@googlegroups.com
Hello, thanks for the effort!

I noticed in your Observer pattern that the event is of the form:
 

PropertyChangeEvent(Object source,
                           String propertyName,
                           Object oldValue,
                           Object newValue)


However, your code example is passing:
 
     new PropertyChangeEvent( source  ==> this,
                                             propertyName ==> property,
                                             oldValue ==> firstName,
                                             newvalue ==> this.firstName = firstName)


As such, you are passing the new setFirstName() value of the name in the "oldValue" parameter. Your object is updated correctly but your listeners are getting the wrong "oldValue" value (see event.getOldValue()).

It should be:

     source  ==> this
     propertyName ==> property
     oldValue ==> this.firstName
     newvalue ==> this.firstName = firstName


This bug exists in both the first name snippit and last name snippit.



-mike

Lars Vogel

unread,
Jun 17, 2013, 5:12:58 AM6/17/13
to vog...@googlegroups.com
Hi Mike,

thanks. 

Fixed.

Best regards, Lars


2013/6/5 mjash <mja...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "vogella" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vogella+u...@googlegroups.com.
To post to this group, send email to vog...@googlegroups.com.
Visit this group at http://groups.google.com/group/vogella.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages