コード例 #1
0
        public void Run()
        {
            Console.WriteLine("Dependency injection principle");
            //bad way
            Console.WriteLine("Bad way:");
            var badXmlHttpService  = new BadWay.XmlHttpService();
            var badNodeHttpService = new BadWay.NodeHttpService();
            var badHttp            = new BadWay.Http(badXmlHttpService, badNodeHttpService);

            badHttp.Get("url");
            badHttp.Post("url");
            badHttp.NodeGet("url");
            badHttp.NodePost("url");
            //good way
            Console.WriteLine("Good way:");
            var goodXmlHttpService  = new GoodWay.XmlHttpService();
            var goodNodeHttpService = new GoodWay.NodeHttpService();
            var goodHttp            = new GoodWay.Http(goodXmlHttpService);

            goodHttp.Get("url");
            goodHttp.Post("url");
            goodHttp = new GoodWay.Http(goodNodeHttpService);
            goodHttp.Get("url");
            goodHttp.Post("url");
            Console.WriteLine();
        }
コード例 #2
0
ファイル: Http.cs プロジェクト: stone1234765/Solid
 public Http(XmlHttpService xmlHttpService, NodeHttpService nodeHttpService)
 {
     XmlHttpService  = xmlHttpService;
     NodeHttpService = nodeHttpService;
 }