Java has the concept of a "bean", which is a class with a no-arg constructor and getter/setter methods. Does this pattern have a more generic name so that, if we're talking to programmers who have never used Java, we can avoid using the term "bean"?
A bean is a little more than a struct though - it's a struct with accessor methods.
Dan
2009-12-14 19:17:26
+1, a bean is exactly a struct. The accessor methods are specific to Java and are not needed in languages that support properties (Python, C#, Scala, etc.).
gooli
2009-12-18 08:00:27
+1
A:
If you look at JavaBean definition, a more "generic" name could be reusable software component (see this tutorial from 1996!), as it provides a well-defined set of services (serialization, accessors, nullary constructor)
But of course all components are not necessarily JavaBean.
They can be also viewed as "property manager", as they allow discovery and access of their properties (through PropertyDescriptor
, as well as managing constraints between properties.
That last aspect allows for JVM-based languages like Scala to adapt their own properties to the JavaBean convention, with scala.reflect.BeanProperty
directive.
VonC
2009-12-14 20:01:25