小编d45*_*453的帖子

楼梯模式实施

我在"自适应代码通过C#"一书中遇到了"Stairway"模式描述,我真的不明白这是如何实现的:

楼梯图案(来源)

所以我有客户端组装:

using ServiceInterface;

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            // Have to create service implementation somehow
            // Where does ServiceFactory belong?
            ServiceFactory serviceFactory = new ServiceFactory();
            IService service = serviceFactory.CreateService();
            service.Do();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

服务接口组件:

namespace Service
{
    public interface IService
    {
        void Do();
    }
}
Run Code Online (Sandbox Code Playgroud)

和服务实现程序集:

using ServiceInterface;

namespace ServiceImplementation
{
    public class PrintService : IService
    {
        public void Do()
        {
            Console.WriteLine("Some work done");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是:如何IService在 …

.net c# decoupling

26
推荐指数
1
解决办法
6740
查看次数

标签 统计

.net ×1

c# ×1

decoupling ×1