計算機科学のブログ

interfaces, casting, and "is" - Making classes keep their promises - class diagrams

Head First C#: A Learner’s Guide to Real-World Programming with C# and .NET Core (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)のChapter 7(interfaces, casting, and “is” - Making classes keep their promises)、p.363(Sharpen Your Pencil)の解答を求めてみる。

コード

Click.cs

using System;
namespace MyFirstConsoleApp
{
    // 1
    public class Click
    {
        public Click()
        {
        }
    }
    class Clack : Click { }

    // 2
    abstract class Top {}
    class Tip : Top { }

    // 3
    abstract class Fee { }
    abstract class Fi : Fee { }

    // 4
    interface Foo { }
    class Bar : Foo { }
    class Baz : Bar { }

    // 5
    interface Zeta { }
    interface Beta { }

    class Alpha : Zeta { }
    class Delta: Alpha, Beta { }
}