Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3696132
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:42:06+00:00 2026-05-19T04:42:06+00:00

I want to make a program that does an order entry system for beverages.

  • 0

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..

alt text

Is there a way to make this picture bigger?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:42:07+00:00Added an answer on May 19, 2026 at 4:42 am

    I can see decorator comes into play here, but I am not too sure about using observer here. It seems forced.

    Several things:

    1. CondimentDecorator need to a have a beverage to decorate. It doesn’t show in your UML. Think of it as a wrapper around something, similar to Adapter pattern. A wrapper need something to wrap on. You clearly didn’t show that.
    2. On your cost behavior interface, why would the concrete decorators implemented it, but the concrete beverages do not, and yet, the beverage has cost also in it? I’d just have beverage interface inherit from cost behavior interface and be done with it.
    3. #2 also applies to the getDescription method… create an IDescribable? or something and have beverage implement that. Decorator will get it through inheritance.
    4. You need to convince me why would a condiment need to know when the price change? At the moment, this seems a bit forced to me. I don’t see how observer is needed here (logically / design-wise). It seems to me that you want to force an observer pattern into this design for no good reason other than you must have it. This is a classic pattern gung-ho thing for someone that just learn about design pattern. Not trying to be offensive, just stating the fact. I was once such a person as well :).

    My suggestion is to read up again on the Head First Design Pattern book (which I think where you get this examples :), very similar domain) and get a better understanding on both patterns and when to use them.

    Below is an example of decorator and observer working together. The drink combination is an implementation of decorator. The ordering system is an observer (where the order will notify the pager and the pager will do something). The scenario here is a StarBuck coffee shop where they’ll give you a pager so you can go around doing something while your drink is being processed and you will get notified by the pager once the drink is ready.

    Save the sample as drink.cs and you can easily compile this using csc ( C:\Windows\Microsoft.Net\Framework\v3….\csc /target:exe /out:drink.exe drink.cs) and run it or use VS or whatever :).

    using System;
    using System.Collections.Generic;
    
    public interface IBeverage
    {
      string GetDescription();
      decimal GetCost();
    }
    
    public abstract class Beverage : IBeverage
    {
      protected string _name;
      protected decimal _cost;
    
      public Beverage(string name, decimal cost)
      {
         _name = name;
         _cost = cost;
      }
    
      public virtual string GetDescription()
      {
        return _name;
      }
    
      public virtual decimal GetCost()
      {
        return _cost;
      }
    }
    
    public class Macchiato : Beverage
    {
      public Macchiato() : base("Macchiato", 3.50m) {}
    }
    
    public abstract class BeverageDecorator : Beverage
    {
      IBeverage _baseBeverage;
    
      public BeverageDecorator(IBeverage baseBeverage) : base("", 0m)
      {
        _baseBeverage = baseBeverage;
      }
    
      public override string GetDescription()
      {
        return _name + " " + _baseBeverage.GetDescription();
      }
    
      public override decimal GetCost()
      {
        return _cost + _baseBeverage.GetCost();
      }
    }
    
    public class Caramel : BeverageDecorator
    {
      public Caramel(IBeverage baseBeverage) : base(baseBeverage) 
      {
         _name = "Caramel";
         _cost = 0.50m;
      }
    }
    
    public class Venti : BeverageDecorator
    {
      public Venti(IBeverage baseBeverage) : base(baseBeverage)
      {
         _name = "Venti";
         _cost = 1.00m;
      }
    }
    
    public class Iced : BeverageDecorator
    {
      public Iced(IBeverage baseBeverage) : base(baseBeverage)
      {
        _name = "Iced";
        _cost = 0.25m;
      }
    }
    
    public class Order
    {
      IBeverage _beverage;
      IPager _pager;
    
      public Order(IBeverage beverage, IPager pager)
      {
        _beverage = beverage;
        _pager = pager;
      }
    
      public IPager Pager
      {
        get { return _pager; }
      }
    
      public IBeverage Beverage
      {
        get { return _beverage; }
      }
    }
    
    public class OrderProcessing
    {
        Queue<Order> orders = new Queue<Order>();
    
        public void NewOrder(IBeverage beverage, IPager pager)
        {
          orders.Enqueue(new Order(beverage, pager));
        }
    
        public void ProcessOrder()
        {
          if (orders.Count > 0)
          {
            var order = orders.Dequeue();
            order.Pager.Update(order);
          }
        }
    }
    
    public interface IPager
    {
      void Update(Order order);
    }
    
    public class VibratingPager : IPager
    {
      string _number;
    
      public VibratingPager(string number)
      {
        _number = number;
      }
    
      public void Update(Order order)
      {
        Console.WriteLine("BUZZZ");
        Console.WriteLine("Your {0} is ready.  Please pay {1} at the cashier after picking it up.", order.Beverage.GetDescription(),order.Beverage.GetCost());
      }
    }
    
    public class Program
    {
      public static void Main(string[] args)
      {  
        var orders = new OrderProcessing();
        var pager1 = new VibratingPager("1");
        var pager2 = new VibratingPager("2");    
    
        orders.NewOrder(new Iced(new Venti(new Caramel(new Macchiato()))), pager1);
        orders.NewOrder(new Venti(new Macchiato()), pager2);
    
        orders.ProcessOrder();
        orders.ProcessOrder();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.