예제 #1
0
        public static void Run()
        {
            var parent = new Person {
                Name = "Adam"
            };
            var child1 = new Person {
                Name = "Abel"
            };
            var child2 = new Person {
                Name = "Cain"
            };

            var relationships = new Relationships();

            relationships.AddParentAndChild(parent, child1);
            relationships.AddParentAndChild(parent, child2);

            // consumer has no direct access to the data in relationships
            // but is aware that this data is accessible via interface
            var children = relationships.FindAllChildrenOf("Adam");

            foreach (var child in children)
            {
                Console.WriteLine($"Adam has a child named {child.Name}");
            }
        }
예제 #2
0
        public IEnumerable <Person> FindAllChildrenOf(Person parent)
        {
            // find all Ana's children

            // 1. metod 1
            // expose private _relationships._relations as public, wich is baaaad
            // ...

            // 2. method 2
            return(_relationships.FindAllChildrenOf(parent.Name));
        }