static void Main(string[] args) { var dragon = new Dragon(); dragon.Age = 0; Console.WriteLine(dragon.Crawl()); Console.WriteLine(dragon.Fly()); dragon.Age = 15; Console.WriteLine(dragon.Crawl()); Console.WriteLine(dragon.Fly()); }
public void Test() { var dragon = new Dragon(); Assert.That(dragon.Fly(), Is.EqualTo("flying")); Assert.That(dragon.Crawl(), Is.EqualTo("too young")); dragon.Age = 20; Assert.That(dragon.Fly(), Is.EqualTo("too old")); Assert.That(dragon.Crawl(), Is.EqualTo("crawling")); }
public void DecoratorTest() { var msg = "fail"; var dragon = new Dragon(); Assert.AreEqual(dragon.Fly(), "flying", msg); Assert.AreEqual(dragon.Crawl(), "too young", msg); dragon.Age = 20; Assert.AreEqual(dragon.Fly(), "too old", msg); Assert.AreEqual(dragon.Crawl(), "crawling", msg); }
public static void MultipleInheritanceExample() { var d = new Dragon(); d.Weight = 123; d.Fly(); d.Crawl(); }
public static void Run() { var d = new Dragon(); d.Weight = 123; d.Fly(); d.Crawl(); }
static void Main(string[] args) { var dragon = new Dragon(); dragon.Weight = 123; dragon.Crawl(); dragon.Fly(); }
static void Main(string[] args) { var dragon = new Dragon { Age = 5 }; dragon.Fly(); dragon.Crawl(); }
public void Crawl_SetWeightBefore_SetsWeightAndReturns() { var dragon = new Dragon(new Bird(), new Lizard()) { Weight = 123 }; var crawled = dragon.Crawl(); Assert.That(crawled, Is.EqualTo("Crawling with weight 123")); }
static void Main(string[] args) { var cb = new CodeBuilder(); cb.AppendLine("class Foo") .AppendLine("{") .AppendLine("}"); WriteLine(cb); WriteLine(); // adapter-decorator MyStringBuilder s = "hello "; s += "world"; // will work even without op+ in MyStringBuilder // why? you figure it out! WriteLine(s); WriteLine(); // multiple inheritance var dragon = new Dragon { Weight = 123 }; dragon.Fly(); dragon.Crawl(); WriteLine(); // dynamic decorator composition var square = new Square(1.23f); WriteLine(square.AsString()); var redSquare = new ColoredShape(square, "red"); WriteLine(redSquare.AsString()); var redHalfTransparentSquare = new TransparentShape(redSquare, 0.5f); WriteLine(redHalfTransparentSquare.AsString()); // static decorator composition ColoredShape <Circle> blueCircle = new ColoredShape <Circle>("blue"); WriteLine(blueCircle.AsString()); TransparentShape <ColoredShape <Square> > blackHalfSquare = new TransparentShape <ColoredShape <Square> >(0.4f); WriteLine(blackHalfSquare.AsString()); ColoredShape <TransparentShape <Circle> > whiteHalfCircle = new ColoredShape <TransparentShape <Circle> >("white"); WriteLine(whiteHalfCircle.AsString()); }