English 中文(简体)
依赖性引起的依赖
原标题:Get dependencies from a dependency

请允许我说一下:PetManagerCat:

class PetManager
{
    PetManager(IBusinessLayer businessLayer, IWashingService washingService);

    IBusinessLayer BusinessLayer;

    IWashingService WashingService;
}

class Cat
{
    Cat(PetManager manager, string name, int levelOfStupidity);
}

现在让我说,我的散射需要洗衣服务,从我的pet管理人那里获得依赖是这样吗?

class Cat
{
    Cat(PetManager manager, string name, int levelOfStupidity)
    {
        this.manager = manager;
        this.name = name;
        this.levelOfStupidity = levelOfStupidity;
    }

    IWashingService WashingService
    {
        get { return this.manager.WashingService; }
    }
}

我强烈怀疑是,......

最佳回答

如所述,Cat是一种具体类别,因此它能够暴露任何意义。 把建筑论视为单纯的特性,是完全明智的事情。

然而,如果实施, 国际法学家委员会强烈怀疑,通过ICat揭露象PetManager这样的依赖性,将是leaky Digest/strong>。

实质上,interfaces充当一种接触分子:。 了解具体类别,而不是接口,是有道理的。 承租者通过建筑商注射,因此永远不能成为接口的一部分,建筑商的签名是我们的自由程度。

问题回答

我猜想这取决于。 通常,当你发现自己有某种人种时,你只是将逻辑分成一个类别,而不是将其分为组成属地。 在你的情况下,你似乎真的应该有一个PetManager的班级,而应该为你的<代码>注入附属地。 Wapingservice和Business Layer直接物体。

我认为,唯一的问题是,如果你将佩特曼纳格作为一种服务,那么目录取决于具体佩特曼纳格,可以提供洗衣服务,这对我来说是较好的。

如果你重新描述控制/独立注射方式的转变(似乎与你一样),你必须考虑权衡。

我猜测,死伤者可能说,你could会因此遇到一些维修问题。 他们肯定不会对仅仅拥有吨参数感到迷惑。 例如,如果你用10种不同的信标使用PetManager,而其中一种信标需要一些特殊功能,导致PetManager改变,那么,你could<>影响到依赖PetManager的其他9个班级,因此更不用说是个别地安置受抚养人。

B. 务实性...... 你们重新做的是,把相关的附属企业集中到另一类,只是通过这种方式,将目标建筑分类和简化。 我 with。 我甚至这样说。

全面披露: 我不想像其他一些人那样死去。 我可能很 her,但比我更清洁的参数和技巧更少。 我感到这种惊讶的是,如果在五年内再次问我的话,我可能会有不同的看法,但现在我已经到了哪里。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...