Пример #1
0
        public void ItThrowsWhenNoMatchSpecified()
        {
            Super b = new SubB();

            var patt = new Pattern <string>
            {
                (SubA _) => "a",
            };

            Assert.Throws <NonExhaustivePattern>(() => patt.Match(b));
        }
Пример #2
0
        public void ITMatchesTheCorrectType()
        {
            Super a    = new SubA(),
                     b = new SubB();

            var patt = new Pattern <string>
            {
                (SubA _) => "a",
                (SubB _) => "b",
            };

            Assert.Equal("a", patt.Match(a));
            Assert.Equal("b", patt.Match(b));
        }
Пример #3
0
        public void FirstMatchingClauseWins()
        {
            Super a = new SubA()
            , b     = new SubB();

            var patt = new Pattern <string>
            {
                (SubA _ ) => "a",
                (object _ ) => "other",
                (SubB _) => "b"
            };

            Assert.Equal("a", patt.Match(a));
            Assert.Equal("other", patt.Match(b));
        }
Пример #4
0
        public void ItCanHaveADefaultClause()
        {
            Super a = new SubA()
            , b     = new SubB();

            var patt = new Pattern <string>
            {
                (SubA _) => "a",
                (SubB _) => "b",
            }
            .Default(() => "other");

            Assert.Equal("a", patt.Match(a));
            Assert.Equal("b", patt.Match(b));
            Assert.Equal("other", patt.Match("hello"));
        }
Пример #5
0
    // Start is called before the first frame update
    void Start()
    {
        SuperA super1 = new SubA(); // 추상 클래스는 자식클래스의 생성자를

        super1.Execute();           //  통해서만 생성 가능.
        // A

        SuperB super2 = new SuperB();   // 일반 클래스.

        super2.Execute1();
        super2.Execute2();  // 가상함수.
        // B-1
        // B-2

        // 파생 클래스에서 재정의한 멤버 함수를 기본 클래스의 포인터로 호출하면
        // 일반적으로 재정의 전의 멤버 함수가 호출된다. 자신의 설계도를 보고 자신을 찾아 온다.
        // 재정의한 후의 멤버 함수가 호출되도록 하기 위해서는
        // 기본 클래스에서 그 함수를 가상 함수로 해둔다.

        SuperB super3 = new SubB();

        super3.Execute1();
        super3.Execute2();  // override 를 이용해서 재정의.
        // B-1
        // C-2

        SubB sub1 = new SubB();

        sub1.Execute1();
        Debug.Log("Execute1 end");
        sub1.Execute2();
        Debug.Log("Execute2 end");
        sub1.Execute3();
        Debug.Log("Execute3 end");
        // C-1
        // Execute1 end
        // C-2
        // Execute2 end
        // B-1
        // C-3
        // Execute3 end
    }
 static void Main(string[] args)
 {
     var a = new SubA();
     var b = new SubB();
 }