[英]How can I get my business objects layer to use the management layer in their methods?
I have a solution in VS2010 with several projects, each making up a layer within my application. 我在VS2010中有一个解决方案,其中包含多个项目,每个项目都构成了我的应用程序中的一层。 I have business entities which are currently objects with no methods, and I have a management layer which references the business entities layer in it's project.
我有目前没有任何方法的对象的业务实体,并且我有一个引用其项目中业务实体层的管理层。 I now think I have designed my application poorly and would like to move methods from helper classes (which are in another layer) into methods I'll create within the business entities themselves.
现在,我认为我的应用程序设计不佳,希望将方法从助手类(位于另一层)转移到我将在业务实体内部创建的方法。
For example I have a VirtualMachine object, which uses a helper class to call a Reboot() method on it which passes the request to the management layer. 例如,我有一个VirtualMachine对象,该对象使用帮助程序类在其上调用Reboot()方法,该方法将请求传递给管理层。 The static manager class talks to an API that reboots the VM.
静态管理器类与重新启动VM的API对话。 I want to move the Reboot() method into the VirtualMachine object, but I will need to reference the management layer:
我想将Reboot()方法移到VirtualMachine对象中,但是我将需要引用管理层:
public void Reboot()
{
VMManager.Reboot(this.Name);
}
So if I add a reference to my management project in my entities project, I get the circular dependency error, which is how it should be. 因此,如果在我的实体项目中添加对管理项目的引用,则会得到循环依赖项错误,应该是这样。 How can I sort this situation out?
如何解决这种情况? Do I need to an yet another layer between the entity layer and the management layer?
我是否需要实体层和管理层之间的另一层? Or, should I just forget it and leave it as it is.
或者,我应该忘掉它并保持原样。
The application works ok now, but I am concerned my design isn't particularly OOP centric and I would like to correct this. 该应用程序现在可以正常运行,但是我担心我的设计不是特别以OOP为中心,我想对此进行更正。
You are correct, you should not make circular references, making another layer might just help you avoid the circular reference error, but it will still be a circular reference, if i understood you correctly. 您是正确的,您不应该进行循环引用,制作另一层可能只是帮助您避免了循环引用错误,但是如果我正确理解您的话,它仍将是循环引用。
I would sit down, draw a map and methods should ONLY call down in layers. 我会坐下来,绘制地图,方法只能分层调用。 That is the most general methods at the "bottom" of the program, and the more specialized you get the higher up in the hierarchy you should put it.
那是程序“最底层”的最通用方法,您越专业化,您应该将其放在层次结构中的较高位置。
The API of the program you are making should be on the bottom of this hierarchy. 您正在制作的程序的API应该位于此层次结构的底部。
You might not need to redesign your whole project. 您可能不需要重新设计整个项目。 But it sounds like you could help yourself with visualizing the structure.
但是,听起来您可以帮助自己可视化结构。
Management layer (as it is the one doing the work) does not seem to fit on the top of Business layer. 管理层(因为这是工作的层)似乎不适合业务层的顶部。 And actually we do not have such a layer above Business layer, we only have facade layer at the top of Business layer - which is not the same as what you need.
实际上,我们在业务层之上没有这样的层,我们仅在业务层的顶部具有外观层 ,这与您所需要的不同。
From what I can see in your project, you need the business layer to use services of the helper class: 从您的项目中可以看到,您需要业务层来使用帮助程序类的服务:
// Business layer
public class VirtualMachineManager
{
IRebooter _rebooter;
public class(IRebooter rebooter)
{
_rebooter = rebooter;
}
}
// helper class
public class Rebooter : IRebooter
{
....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.