4

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"?

Todd R
  • 18,236
  • 8
  • 31
  • 39

4 Answers4

3

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

In C, a struct. In VB, structure.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • A bean is a little more than a struct though - it's a struct with accessor methods. – Dan Dec 14 '09 at 19:17
  • +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.). – elifiner Dec 18 '09 at 08:00
  • Altough the bean construction is often used as a replacement for a struct, this is really an antipattern: Like all OO classes, most beans should encapsulate behaviour, not be a dumb data container. Check the reusable softwar ecomponent below for a much better answer. Consider a Bean the Java equivalent of a Windows COM component. – hyperman Oct 24 '12 at 13:50
0

Altough the bean construction is often used as a replacement for a struct, this is really an antipattern: Like all OO classes, most beans should encapsulate behaviour, not be a dumb data container. Originally, a Bean was positioned as the Java equivalent of a Windows COM component, whose properties could be discovered by a containing framework.

hyperman
  • 1,324
  • 1
  • 11
  • 21
0

I think it is related to Object-relational mapping which is also available in other languages or even areas (like CAD).

ntl01
  • 3
  • 1