– HFDP observer and decorator
– according to HFDP, these two patterns are considered following the open-close principle
– the observer is essentially a callback
– the java built-in observer needs to implement the Observer intf
– the java observable requires inheritance containing a “setChanged()” api which seems odd
– setChanged is meant to flexible in how to update observers by allowing optimizing notif. Sounds like a tuning api to control the sensitivity of triggering the callbacks.
– call setChanged() first, then notifyObservers()
– the decorator example in java JDK is the various kind of InputStreams, e.g. FileInputStream, StringBufferInputStream, ByteArrayInputStream
– the mocha example is calculating the cost by return .20 + beverage.cost(). “beverage” was set and saved as an attribute. This looks essentially a link list of beverages while the “cost()” api does the job of calculating beverage.cost() of the next beverage.
– drawback of decorators is, resulting in a large number of small classes that can be overwhelming to a user.