Observer pattern used with decorator pattern
- by icelated
I want to make a program that does an order entry system for beverages. ( i will probably do description, cost)
I want to use the Decorator pattern and the observer pattern.
I made a UML drawing and saved it as a pic for easy viewing. This site wont let me upload as a word doc so i have to upload a pic - i hope its easily viewable....
I need to know if i am doing the UML / design patterns correctly before moving on to the coding part.
Beverage is my abstract component class.
Espresso, houseblend, darkroast are my concrete subject classes..
I also have a condiment decorator class
milk,mocha,soy,whip. would be my observer? because they would be interested in data changes to cost?
Now, would the espresso,houseblend etc, be my SUBJECT and the condiments be my observer?
My theory is that Cost is a changes and that the condiments need to know the changes?
So, subject = esspresso,houseblend,darkroast,etc.. // they hold cost()
Observer = milk,mocha,soy,whip? // they hold cost()
would be the concrete components and the
milk,mocha,soy,whip? would be the decorator!
So, following good software engineering practices "design to an interface and not implementation" or "identify things that change from those that dont"
would i need a costbehavior interface?
If you look at the UML you will see where i am going with this and see if i am implementing observer + Decorator pattern correctly? I think the decorator is correct.
since, the pic is not very viewable i will detail the classes here:
Beverage class(register observer, remove observer, notify observer, description)
these classes are the concrete beverage classes
espresso, houseblend,darkroast, decaf(cost,getdescription,setcost,costchanged)
interface observer class(update) // cost?
interface costbehavior class(cost) // since this changes?
condiment decorator class( getdescription)
concrete classes that are linked to the 2 interface s and decorator are:
milk,mocha,soy,whip(cost,getdescription,update)
these are my decorator/ wrapper classes.
Thank you..
Is there a way to make this picture bigger?