You can edit almost every page by Creating an account. Otherwise, see the FAQ.

BaseBean

From EverybodyWiki Bios & Wiki



In object-oriented programming, inheritance should be used for "IS-A" relationships, not "HAS-A" relationships. A BaseBean is a utility class from which concrete entities have been derived via subclassing, creating a false implication that the derived classes represent subtypes of the utility class in the business domain. 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). For example, if a utility class exists called DatabaseUtils, which contains utility methods for setting up and tearing down database connections, and other classes such as Employee extend from it, DatabaseUtils is a BaseBean, because in the real world, an employee is not a "database utils".

Proper design suggests that the inherited functionality should be provided via delegation instead.

A class should not inherit from another class simply because the parent class contains functionality needed in the subclass, as the inheriting class may behave improperly when used as a replacement of the parent class, thus violating the Liskov substitution principle. Instead, delegation (has-a relationship) could be used to obtain the business logic or data structure that is required. In other words, this case warrants composition over inheritance. In some cases, in Java, a utility class containing only static methods can be created to contain the 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. It may be that it needs to be refactored as a more meaningful class, and referenced rather than extended.

See also[edit]

  • The CallSuper anti-pattern – in which a derived class has the requirement to call into the parent class to complete its work

References[edit]

  • Rajiv Ramnath, Cheyney Loffing, Beginning IOS Programming For Dummies, p.105, John Wiley & Sons, 2014 ISBN 1118799275 Search this book on ..






This article "BaseBean" is from Wikipedia. The list of its authors can be seen in its historical. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.