BaseBean
Encyclopedia
In object-oriented programming
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

, a BaseBean is a utility object from which concrete entities are derived (via subclassing). Proper design
Design pattern (computer science)
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that...

 suggests that the inherited functionality should be provided via delegation instead. The BaseBean is an example of an anti-pattern
Anti-pattern
In software engineering, an anti-pattern is a pattern that may be commonly used but is ineffective and/or counterproductive in practice.The term was coined in 1995 by Andrew Koenig,...

 (where the "Bean" part of the name comes from the standard Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 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
Fragile base class
The fragile base class problem is a fundamental architectural problem of object-oriented programming systems where base classes are considered "fragile" because seemingly safe modifications to a base class, when inherited by the derived classes, may cause the derived classes to malfunction...

 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
Has-a
In database design and object oriented program architecture, has-a is a relationship where one object "belongs" to another object , and behaves according to the rules of ownership. In simple words, has-a relationship in an object is called a member field of an object...

 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 a static utility class
Utility class
In computer programming, a utility class is a class that defines a set of methods that perform common, often re-used functions. Most utility classes define these common methods under static scope...

 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
CallSuper
Call super is a code smell or anti-pattern of object-oriented programming. Call super is a design pattern in which a particular class stipulates that in a derived subclass, the user is required to override a method and call back the overridden function itself at a particular point...

anti-pattern, in which a derived class has the requirement to call into the parent class to complete its work.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK