I'm not fond of the redundancy in "dogName" when you already know that you are dealing with an object of type "Dog", just "name" should suffice. Of course that means your constructor would need to have
this.name = name;
Your class is almost immutable. I wouldn't expect name and breed to change (I suppose name could change). Age would change a lot unless you stored it as something like birthYear or dateOfBirth and make getAge() calculate age on the fly. Then even age could be made immutable. Making your class immutable means you can do away with all the setter methods and keep the getter methods. This might eliminate the need for bark() unless you need it for another purpose.
@ Carey Brown: Thank you for your comments but it is just an example to show my concern.
@ Tim Moores: Thanks for your fast answer. You are right, but imagine the class having. a hundred of fields. I would like to know some mechanism that allows me to launch bark() when one of the fields mutate without having to write bark() in every setter method. I think it would be a more ellegant approach.
Even with an observer you would have to modify each set method to notify the observer that it has been called.
I mean, unless you used some sort of wrapper for each attribute (I think JavaFX does something like that with its properties?).
AOP is a bit messy to set up, but is the most transparent.
Another technique I use is to add a boolean "dirty" property to the bean and set dirty to true when any of the interesting property values is modified. Then I can simply call isDirty(). That works well when I may want to change multiple properties and only fire one event. Plus it doesn't require me to register listener callbacks for a PropertyChangeListener list.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop