• Post Reply Bookmark Topic Watch Topic
  • New Topic

Decorator Design Pattern  RSS feed

 
Levent Erguder
Greenhorn
Posts: 10
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys!
i have a task about decorator design pattern.

fortunately it looks like head first desing pattern book example. when i see document , i have realized it.

https://www.safaribooksonline.com/library/view/head-first-design/0596007124/ch03.html

i have some predefined beverage types like
DRIPCOFFEE
DECAF
HOTCHOCOLATE

upto now it is OK.
but i have a problem , i have to add new type of beverage and condiments via a form page.
like GREENTEA , BLACKTEA , LEMON.. they all have price, description etc..
But i dont have these classes , of course it is imposible create all classes for all beverages and condiments -)

i have asked an expert java developer, he suggested "type object design pattern". i didnt found too much about it.

so did you face to like this problem ?
do you know about type object design pattern

thank you.
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks like it is for a homework assignment. Is it?

Levent Erguder wrote:Hi guys!
i have a task about decorator design pattern.

fortunately it looks like head first desing pattern book example. when i see document , i have realized it.

https://www.safaribooksonline.com/library/view/head-first-design/0596007124/ch03.html

i have some predefined beverage types like
DRIPCOFFEE
DECAF
HOTCHOCOLATE

upto now it is OK.
but i have a problem , i have to add new type of beverage and condiments via a form page.
like GREENTEA , BLACKTEA , LEMON.. they all have price, description etc..
But i dont have these classes , of course it is imposible create all classes for all beverages and condiments -)

i have asked an expert java developer, he suggested "type object design pattern". i didnt found too much about it.

so did you face to like this problem ?
do you know about type object design pattern

thank you.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Levent Erguder wrote:so did you face to like this problem ?

Yes.

do you know about type object design pattern

No, but I found a reference to it via Google ("type object design pattern") here; and it seems to cover similar ground to your problem (or at least what you seem to assume it is).

However, since your title was about the Decorator pattern, I'm not exactly sure how relevant it is, and you appear to be trying to solve a problem that may not exist in your case.

How many "condiments" can there be to a cup of coffee? A dozen perhaps, but certainly not hundreds.
How often are you likely to have new ones? Rarely, I suspect. A cup of coffee is a cup of coffee, and you're not likely to be offering one with curry powder or parsley or meat paste.

My suggestion: Stick to the exercise you've been given, and worry about "type Objects" later. It's good that you're thinking about these things, but as
Antoine de Saint-Exupery wrote:"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away".

So stick to the task you've been given, and don't look for problems that may not exist.

HIH

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!