...
Wiki Markup |
---|
The class {{Provider}} inherits the {{put()}} and {{remove()}} methods from {{Hashtable}} and adds security manager checks to each. The security manager checks ensure that malicious code cannot add or remove the mappings. When {{entrySet()}} was introduced, it became possible for untrusted code to remove the mappings from the {{Hashtable}} because {{java.security.Provider}} did not override this method to provide the necessary security manager check \[[SCG 2007|AA. Java References#SCGBibliography#SCG 07]\]. This problem is commonly know as a "fragile class hierarchy" in other object-oriented languages such as C++. |
...
Wiki Markup |
---|
This compliant solution recommends the use of a design pattern called composition and forwarding (sometimes also referred to as delegation) \[[Lieberman 1986|AA. Java References#LiebermanBibliography#Lieberman 86]\] and \[[Gamma 1995|AA. JavaBibliography#Gamma References#Gamma 95, p. 20]\]. A new _forwarder_ class that contains a {{private}} member field of the {{Calendar}} type is introduced. Such a composite class constitutes _composition_. In this example, the field refers to {{CalendarImplementation}}, a concrete instantiable implementation of the {{abstract}} {{Calendar}} class. A wrapper class called {{CompositeCalendar}} is also introduced. It consists of the same overridden methods that constituted {{CalendarSubclass}} in the preceding noncompliant code example. |
...
Wiki Markup |
---|
\[[SCG 2007|AA. Java References#SCGBibliography#SCG 07]\] Guideline 1-3 Understand how a superclass can affect subclass behavior \[[Bloch 2008|AA. JavaBibliography#Bloch References#Bloch 08]\] Item 16: "Favor composition over inheritance" \[[Gamma 1995|AA. Java References#GammaBibliography#Gamma 95]\] \[[Lieberman 1986|AA. Java References#LiebermanBibliography#Lieberman 86]\] |
...
OBJ06-J. Compare classes and not class names 08. Object Orientation (OBJ) OBJ08-J. Avoid using finalizers