Java Reference
In-Depth Information
Listing 14.9. Recloseable Gate Using Wait and Notifyall .
Astate-dependentclassshouldeitherfullyexpose(anddocument)itswaitingandnotification
protocols to subclasses, or prevent subclasses from participating in them at all. (This is an
extension of “design and document for inheritance, or else prohibit it” [EJ Item 15].) At the
very least, designing a state-dependent class for inheritance requires exposing the condition
queues and locks and documenting the condition predicates and synchronization policy; it
may also require exposing the underlying state variables. (The worst thing a state-dependent
class can do is expose its state to subclasses but not document its protocols for waiting and
notification; this is like a class exposing its state variables but not documenting its invari-
ants.)
One option for doing this is to effectively prohibit subclassing, either by making the class
final or by hiding the condition queues, locks, and state variables from subclasses. Other-
wise, if the subclass does something to undermine the way the base class uses notify , it
Search WWH ::




Custom Search