0

So I have a film class that has the data members : id, name, genre, type, and price.

Is it possible for me to use the observer design pattern to update the price of all these films. So i want to select an option to add the promotion all the films to be half price for customers. I am able to do this normally but have to try use some design patterns for this project.

Update:

Sorry if I wasn't clear. I want to know if I can use the observer design pattern to update the price of all the film instances of my Film Class. So when the staff member signs into the system he has the option to add a film promotion. So when he selects "All Films Half Price" it will update all the instances of the film class with the new price.

I'm not sure if this is even possible with the observer but I have to use some design patterns in this project and thought that I could make use of the observer here

Smern
  • 18,746
  • 21
  • 72
  • 90
SG_2894
  • 29
  • 2
  • I'm having trouble understanding your question. You want to update a bunch of different movies to have a discount at the same time? – John Farkerson Apr 24 '16 at 20:12
  • 1
    I'm having trouble seeing what it is about the Observer pattern that makes you consider it for a problem of the form "do something to all instances of C". – John Bollinger Apr 24 '16 at 20:15
  • Check out [Head First Design Patterns](http://shop.oreilly.com/product/9780596007126.do) chapter about Decorator Pattern. Looks very similar to your issue. – Sergii Bishyr Apr 24 '16 at 20:21
  • Classic denormalization problem. You don't want to do this at all. You want to provide a *discount* at the *checkout.* *Not* change the price of every film according to the user. – user207421 Apr 28 '16 at 21:13

1 Answers1

0

If Film promotion is an event and Film instances are Observers interested to the event, then I feel Observer pattern can be applied to the situation posted in the question. An interface can be designed as below:

public interface PromotionObserver{
    void notify();
}

This interface can be implemented by class Film. If there are various sub classes of Film then notify() can be implemented by all the sub classes and in the implementation the price related changes specific to sub classes can be made. If the change is generic like price is simply half of the original price then simply the parent class can implement the notify() and code like price = price/2; will suffice.

The class responsible for handling the Film promotion event can have a List<PromotionObserver> promotionObservers; along with methods like registerPromotionObserver(PromotionObserver promotionObserver); When Staff member signs in and decides to make all or few films as promotional (may be with click of buttons of check boxes in UI side) then in a loop, promotionObservers can be iterated and each on each registered object of PromotionObserver notify() can be invoked.

nits.kk
  • 5,204
  • 4
  • 33
  • 55
  • @Shaun Gilbert does my answer solves your issue or you want further help. Do let us know in case more information is needed – nits.kk Apr 27 '16 at 14:36