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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -