コード例 #1
0
        public Cat NestedCats()
        {
            Cat grandMother = new Cat();
            Cat mother = new Cat();
            Cat daughter = new Cat();
            Cat grandDaughter = new Cat();
            Cat son = new Cat();

            daughter.AddDescendant(grandDaughter);

            mother.AddDescendant(son);
            mother.AddDescendant(daughter);

            grandMother.AddDescendant(daughter);

            return grandMother;
        }
コード例 #2
0
        public List<Cat> Cyclic()
        {
            var catA = new Cat
            {
            };

            var catB = new Cat
            {
            };

            var catC = new Cat
            {
            };

            catC.AddDescendant(catA);
            catA.AddDescendant(catC);

            return new List<Cat>
            {
                catA,
                catB,
                catC
            };
        }
コード例 #3
0
 public void AddDescendant(Cat cat)
 {
     _descendants.Add(cat);
 }