• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt about Design Pattern

 
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a doubt about decorator design pattern.


Codes with decorator


Codes without decorator



This is the main class


With both set of classes, when we execute main class the result will be the same. If that is the result, what the decorator is?
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Sreeraj G H",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You might also think about making a shorter question, otherwise known as isolating the problem. I know that when I see a post as long as yours, I tend to ignore it until I have enough time to read it. There are many other ranchers who feel the same way.

Andrew
JavaRanch Sheriff
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sreeraj,

you may not have noticed, but the second version of code, you provided, uses the decorator pattern as well

The original design makes a distinction between the basic beverage (the coffee variations) and the add-ons (milk, whip and so on), whereas you combined all of them to extend a common base class.

Although your approach is valid as well, I yould prefer the original one, as it is clearer in terms of valid variations: with your approach you could shake a "Mocha with Decaf" - kind of odd, isn't it

Greetings,
Frank
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic