Simon Joseph Aquilina wrote:As you can see from the above example both approaches work fine to add an Apple to a Tree. The book seems to indicate that the second approach - addApple(Apple a) - is not correct since the 'add' prefix should only be used for listeners. In other words it works, compiles, but not as should.
The JavaBean standard is not a "best practices" naming convention. Its a standard that allows tools to introspect an object, and figure out what to do. In that regard, it has the concept of properties and the concept of listeners -- and it supports a naming convention for those concepts.
Furthermore, the naming convention is more for convenience, most beans with complex property/listeners/method naming requirements, take the extra steps of providing a beaninfo which allows the javabean to specify exactly what name to use for what.
It is generally recommend to follow the standard, just in case, in the future, you want convert the java class into a java bean. If you disagree with the requirements of the standard, either don't follow it, (or if you must, then provide a beaninfo for it).