BaseBean

BaseBean

In object-oriented programming, a BaseBean is a utility object from which concrete entities are derived (via subclassing). Proper design suggests that the inherited functionality should be provided via delegation instead. The BaseBean is an example of an anti-pattern (where the "Bean" part of the name comes from the standard Java naming convention for a generic entity object, or JavaBean).

Using inheritance causes the derived class to rely on the internals of a base class which may be out of the control of the developer. While the utility classes are typically stable and fairly similar across implementations, some innocuous change in the future could break the derived class (since the relationship is not well defined). In addition, it muddies the business meaning of the derived class. For example, an order is not a vector, although an order may contain a vector of line items.

A class should not inherit from another class simply because the parent class contains functionality needed in the subclass. Instead, delegation (has-a relationship) should be used to obtain the business logic or data structure that is required. In technical terms, this case warrants composition over inheritance. In some cases static Utility class can be created to contain necessary functionality. Object-oriented programming emphasizes that objects should be meaningful and should communicate with each other in the way that resembles the real-world entities they are emulating. A "BaseBean" is not a real-world object, nor is it descriptive. Likely, it needs to be refactored as a more meaningful class and referenced rather than extended.

This pattern is somewhat related to the CallSuper anti-pattern, in which a base class has the requirement to call into the parent class to complete its work.


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Anti-pattern — For the book, see AntiPatterns. In software engineering, an anti pattern (or antipattern) is a pattern that may be commonly used but is ineffective and/or counterproductive in practice.[1][2] The term was coined in 1995 by Andrew Koenig,[3]… …   Wikipedia

  • Antipatrón de diseño — Saltar a navegación, búsqueda Un antipatrón de diseño es un patrón de diseño que invariablemente conduce a una mala solución para un problema. Al documentarse los antipatrones, además de los patrones de diseño, se dan argumentos a los diseñadores …   Wikipedia Español

  • Антипаттерн — Возможно, эта статья содержит оригинальное исследование. Добавьте ссылки на источники, в противном случае она может быть выставлена на удаление. Дополнительные сведения могут быть на странице обсуждения. (25 мая 2011) …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”