R
rodchar
hey all,
i'm trying to use the decorator pattern example from a book but it's using
java for the syntax. below is my attempt in c# but not having any luck:
using System;
namespace Ch3Decorator
{
public class Computer
{
public string Description()
{
return "computer";
}
}
public abstract class ComponentDecorator : Computer
{
public abstract string Description();
}
public class Disk : ComponentDecorator
{
Computer c;
public Disk(Computer c)
{
this.c = c;
}
public new string Description()
{
return c.Description() + " " + "and a disk";
}
}
public class Program
{
static void Main(string[] args)
{
Computer c = new Computer();
c = new Disk(c);
Console.WriteLine("I'm getting a {0}", c.Description());
}
}
}
(color code format: http://pastebin.com/md08b089)
all i'm trying to get it to do is say "i'm getting a computer and a disk" to
demonstrate extending the Computer class.
thanks,
rodchar
i'm trying to use the decorator pattern example from a book but it's using
java for the syntax. below is my attempt in c# but not having any luck:
using System;
namespace Ch3Decorator
{
public class Computer
{
public string Description()
{
return "computer";
}
}
public abstract class ComponentDecorator : Computer
{
public abstract string Description();
}
public class Disk : ComponentDecorator
{
Computer c;
public Disk(Computer c)
{
this.c = c;
}
public new string Description()
{
return c.Description() + " " + "and a disk";
}
}
public class Program
{
static void Main(string[] args)
{
Computer c = new Computer();
c = new Disk(c);
Console.WriteLine("I'm getting a {0}", c.Description());
}
}
}
(color code format: http://pastebin.com/md08b089)
all i'm trying to get it to do is say "i'm getting a computer and a disk" to
demonstrate extending the Computer class.
thanks,
rodchar