2017年8月12日 星期六

[C#] ClassDiagram on Visual Studio

  • ClassDiagram
    • 視覺化的介面
    • 優點:視覺化設計方式,將程式架構圖像化
    • VS2017:選擇 Class Diagram
    • Class Diagram 介面
    
    /// 
        /// The 'AbstractFactory' abstract class
        /// 
        abstract class AbstractFactory
        {
            public abstract AbstractProductA CreateProductA();
            public abstract AbstractProductB CreateProductB();
        }
    
    
        /// 
        /// The 'ConcreteFactory1' class
        /// 
        class ConcreteFactory1 : AbstractFactory
        {
            public override AbstractProductA CreateProductA()
            {
                return new ProductA1();
            }
            public override AbstractProductB CreateProductB()
            {
                return new ProductB1();
            }
        }
    
        /// 
        /// The 'ConcreteFactory2' class
        /// 
        class ConcreteFactory2 : AbstractFactory
        {
            public override AbstractProductA CreateProductA()
            {
                return new ProductA2();
            }
            public override AbstractProductB CreateProductB()
            {
                return new ProductB2();
            }
        }
    
        /// 
        /// The 'AbstractProductA' abstract class
        /// 
        abstract class AbstractProductA
        {
        }
    
        /// 
        /// The 'AbstractProductB' abstract class
        /// 
        abstract class AbstractProductB
        {
            public abstract void Interact(AbstractProductA a);
        }
    
    
        /// 
        /// The 'ProductA1' class
        /// 
        class ProductA1 : AbstractProductA
        {
        }
    
        /// 
        /// The 'ProductB1' class
        /// 
        class ProductB1 : AbstractProductB
        {
            public override void Interact(AbstractProductA a)
            {
                Console.WriteLine(this.GetType().Name +
                  " interacts with " + a.GetType().Name);
            }
        }
    
        /// 
        /// The 'ProductA2' class
        /// 
        class ProductA2 : AbstractProductA
        {
        }
    
        /// 
        /// The 'ProductB2' class
        /// 
        class ProductB2 : AbstractProductB
        {
            public override void Interact(AbstractProductA a)
            {
                Console.WriteLine(this.GetType().Name +
                  " interacts with " + a.GetType().Name);
            }
        }
    
        /// 
        /// The 'Client' class. Interaction environment for the products.
        /// 
        class Client
        {
            private AbstractProductA _abstractProductA;
            private AbstractProductB _abstractProductB;
    
            // Constructor
            public Client(AbstractFactory factory)
            {
                _abstractProductB = factory.CreateProductB();
                _abstractProductA = factory.CreateProductA();
            }
    
            public void Run()
            {
                _abstractProductB.Interact(_abstractProductA);
            }
        }
    • Class Diagram 產生出來的結果
    • Class Diagram 可以匯出圖形

    • 產出的圖形,可幫助開發人員快速的理解程式架構
  • Ref
    • 恆逸 - U2941a 

沒有留言:

張貼留言