Back to list
Views:   7.2K
Replies:  1
Archived

Decorator example from Design Pattern Framework

I hope that I don't get moved to the 'hair-splitters' section for that question, but as we're talking here about very basic principles, I just wanted to get everything right :)

In the Design Pattern Framework, there's an example in the solution DoFactory.HeadFirst.Decorator.Starrbuzz. That example contains a base-class, which is called Beverage.

My question is now, why don't we declare this base-class as abstract, as we're never going to have instance of a sole Beverage, but only drinks like e.g. Espresso, DarkRoast, ...?
public class Beverage
{
   public virtual string Description { get; protected set; }
   public virtual double Cost { get; protected set; }
}

public class DarkRoast : Beverage
{
   public DarkRoast()
   {
      Description = "Dark Roast Coffee";
      Cost = 0.99;
   }
}

 
Florian Schaeffler, Feb 27, 2012
Reply 1
I have not seen the full source of the Beverage class, but an abstract class provides a base framework (optionally with partial implementation) that other classes can share via inheritance. In the above case, Beverage case can be abstract too since it is not instantiated and provides base properties for beverages.

Hope this helps?

Siva M, Mar 01, 2012


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.2.2