• Post Reply Bookmark Topic Watch Topic
  • New Topic

For decorator pattern better Interface or Abstract Class?  RSS feed

 
Greenhorn
Posts: 20
Java jQuery Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I want to create a simply drinks shop but I have some doubts about the class structure.

I have 3 types of coffee with some CoffeeDecorator and 3 Types of Cocktails with some DrinksDecorator.

Do you think is better to use also the Composite pattern for the 3 types of coffee and another composite for cocktails?

For the drinks, is better to have a Interface Drinks or an Abstract Class?

Thanks in advance!
M.Lars
 
Michael Lars
Greenhorn
Posts: 20
Java jQuery Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any Idea?
 
Ranch Hand
Posts: 209
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,

It depends on the implementation details,

You could use both an interface and an abstract class,

You could use an interface to define what the method signatures that other methods can call,

The abstract class could then be used for common code between the 3 classes, if there is no common code then its better just to have an interface but if there is common code then its good to have an abstract class,

Hope this helps,

Niall
 
Michael Lars
Greenhorn
Posts: 20
Java jQuery Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Niall!

I'm attaching an image where I made a simply structure.

And my question is, will this structure work? - Is ok if in the future this project will be expanded for an invoice print, or other drinks?

Thanks again, I appreciated it!
mo.jpg
[Thumbnail for mo.jpg]
 
Michael Lars
Greenhorn
Posts: 20
Java jQuery Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or is better this class diagram?

Thank you!
78.png
[Thumbnail for 78.png]
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either will work. I can't off the top of my head think of a reason to favor one over the other. I would probably use the second approach, just because the decorator needs to appear as if it is the thing it decorates, so why not make that literally true.
 
Michael Lars
Greenhorn
Posts: 20
Java jQuery Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!