디자인 모드 - 외관 모드 (Facade)

1812 단어
4. 567917. 핵심 사상 은 서로 다른 등급 을 나 누 어 결합 을 낮 추 는 것 이다
코드 예시
using System;
namespace Factory1
{
      //               
    public class Facade
    {
        SubSystemOne one;
        SubSystemTwo two;
        SubSystemThree three;
        SubSystemFour four;
        public Facade ()
        {
            one = new SubSystemOne();
            two = new SubSystemTwo ();
            three = new SubSystemThree ();
            four = new SubSystemFour ();
        }
        public void MethodOne(){
            Console.WriteLine ("MethodA");
            one.MethodOne ();
            two.MethodTwo ();
            three.MethodThree ();
            four.MethodFour ();
        }
        public void MethodTwo(){
            Console.WriteLine ("MethodB");
            one.MethodOne ();
            two.MethodTwo ();
            three.MethodThree ();
            four.MethodFour ();
        }
    }
    class SubSystemOne{
        public void MethodOne()
        {
            Console.WriteLine ("Method One");
        }
    }
    class SubSystemTwo{
        public void MethodTwo(){
            Console.WriteLine("Method Two");
        }
    }
    class SubSystemThree{
        public void MethodThree(){
            Console.WriteLine("Method Three");
        }
    }
    class SubSystemFour{
        public void MethodFour(){
            Console.WriteLine("Method Four");
        }
    }
    class MainClass
    {
        public static void Main (string[] args)
        {
            Facade f = new Facade ();
            f.MethodOne ();
            f.MethodTwo ();
            Console.Read ();
        }
    }
}

운행 결과
MethodA Method One Method Two Method Three Method Four MethodB Method One Method Two Method Three Method Four

좋은 웹페이지 즐겨찾기