/// <summary>
        /// 安全式的 测试.
        /// </summary>
        private static void TestSafe()
        {
            // Create a tree structure
            Safe.Composite root = new Safe.Composite("我是根结点(树枝结点)");
            root.Add(new Safe.Leaf("我是叶子结点 A"));
            root.Add(new Safe.Leaf("我是叶子结点 B"));
            Safe.Composite comp = new Safe.Composite("我是树枝结点 X");

            comp.Add(new Safe.Leaf("我是叶子结点 XA"));
            comp.Add(new Safe.Leaf("我是叶子结点 XB"));
            root.Add(comp);

            root.Add(new Safe.Leaf("我是叶子结点 C"));

            // Add and remove a leaf
            Safe.Leaf l = new Safe.Leaf("我是叶子结点 D");
            root.Add(l);
            root.Remove(l);

            // Recursively display nodes
            root.Display(1);
        }
Exemple #2
0
        /// <summary>
        /// 安全式的 测试.
        /// </summary>
        private static void TestSafe()
        {
            // Create a tree structure
            Safe.Composite root = new Safe.Composite("我是根结点(树枝结点)");
            root.Add(new Safe.Leaf("我是叶子结点 A"));
            root.Add(new Safe.Leaf("我是叶子结点 B"));
            Safe.Composite comp = new Safe.Composite("我是树枝结点 X");

            comp.Add(new Safe.Leaf("我是叶子结点 XA"));
            comp.Add(new Safe.Leaf("我是叶子结点 XB"));
            root.Add(comp);

            root.Add(new Safe.Leaf("我是叶子结点 C"));

            // Add and remove a leaf
            Safe.Leaf l = new Safe.Leaf("我是叶子结点 D");
            root.Add(l);
            root.Remove(l);

            // Recursively display nodes
            root.Display(1);
        }