尝试使用"Head First Design Patterns"一书(用Java编写)中的代码在C#中实现装饰器模式.
我刚刚开始使用C#,因此我仍然对语法不熟悉,所以我不确定为什么我不能让下面的注释代码行工作.
这是Decorator模式中的第一个抽象基类及其派生类:
using System;
public abstract class Beverage
{
private String m_description;
// get a description of the beverage
public virtual String Description { get { return m_description; } }
// calculate cost of the beverage
public abstract double Cost();
}
// HouseBlend coffee implements Beverage
public class HouseBlend : Beverage
{
// Constructor
public HouseBlend() { m_description = "House Blend"; }
// calculate base cost of House Blend
public override double Cost() { return 0.89; …Run Code Online (Sandbox Code Playgroud)