design patterns - When should I use decorator / observer? -
there these 2 pattern : observer , decorator. both enables me add action after done (or before decorator). implementation differs. when should use decorator or observer.
so far came :
decorator : add business functionnality service that'll change state of entities used decorated service.
observer : update view model / gui, connect infrastructure service, change state of other entities
for instance in booking level have booking entity, first service create booking , mark accomodation not available :
- sending email customer / owner : observer
- using customers cc automating payment : decorator
- updating view/cache accomodations availabilities : observer
- mark booking "must validated or validated" : decorator
am right ?
these 2 patterns not similar. should use decorator if need additional responsibilities object while keeping same interface. don't see why need keep same interface in case, therefore against decorator.
observer fine when want notified of change in object (for example "add action after done"), although there simpler ways.
Comments
Post a Comment