简体   繁体   English

多层应用程序设计

[英]Multi-tier Application Design

Before everyone throws stones at me, I have searched Google / MSDN / StackOver flow for related questions and answers but none of them suited my needs. 在所有人向我投掷石块之前,我已经在Google / MSDN / StackOver流中搜索了相关的问题和答案,但是没有一个适合我的需求。

I'm working on a rather large application in C# - Windows Forms that is currently divided into the following: 我正在使用C#-Windows窗体中的一个相当大的应用程序,该应用程序目前分为以下几类:

  1. Data-Layer 数据层
  2. Domain-Layer 域层
  3. UI-Layer UI层

Basically in my current situation the roles of this layers are the following 基本上在我目前的情况下,这些层的作用如下

  1. The Data-Layer's responsability is to communicate with the data-store, basically CRUD operations. 数据层的责任是与数据存储通信,基本上是CRUD操作。
  2. The Domain-Layer's responsability is to hold the model of our objects, create the objects, apply business-rules etc. 域层的责任是保存我们对象的模型,创建对象,应用业务规则等。
  3. The UI-Layer, well, basically this is what the user sees and interacts with. UI层基本上就是用户看到并与之交互的对象。

My problem is the following: 我的问题如下:

From the UI Layer the user has access to fields like: Name, Project Name, Project Number which basically are TextBoxes, Calendars etc - all of them are UI Components. 用户可以从UI层访问诸如名称,项目名称,项目编号之类的字段,这些字段基本上是文本框,日历等-它们都是UI组件。

After the input of the user I call a method named: AddExplorerNode(string name, string projectName, int projectNumber) which resides in the Domain-Layer. 在用户输入之后,我调用一个名为: AddExplorerNode(string name, string projectName, int projectNumber) ,该方法位于Domain-Layer中。 This method is responsible based on the passed parameters to create an ExplorerNode Object ( a "special" TreeNode ) which requires the passed parameters to actually be valid. 此方法负责根据传递的参数来创建一个ExplorerNode对象 (“特殊” TreeNode),该对象要求传递的参数实际上是有效的。

After the object has been created, sanitized, validated etc - the same method mentioned above passes the created object to the Data-Layer which pushes it to a Cache-Repository and then to persists it to the data-store if everything went OK in the Cache. 在创建,清理,验证对象后-与上述相同的方法将创建的对象传递到Data-Layer,然后将其推送到Cache-Repository,然后如果一切正常,则将其持久保存到数据存储中快取。

So until now, basically everything is separated UI -> Domain -> DataLayer. 所以直到现在,基本上所有东西都是分开的UI-> Domain-> DataLayer。

My question is, could I replace the signature of the Domain method from 我的问题是,我可以替换Domain方法的签名吗?

AddExplorerNode(string name, string projectName, int projectNumber) to AddExplorerNode(TreeNode node) and based on the TreeNode object and its properties, construct the actual object I need ? AddExplorerNode(string name, string projectName, int projectNumber)AddExplorerNode(TreeNode node)并基于TreeNode对象及其属性构造我需要的实际对象? I'm asking this because, if the Domain-Layers knows about the UI ( in this case the TreeNode UI Component ) basically we break the separation. 我之所以这样问是因为,如果Domain-Layers知道UI(在本例中为TreeNode UI Component),那么我们基本上就打破了分离。

For example, if next year we swap WindowsForms to a Console Application , then the project is broken due to the fact that a Console Application will not have a TreeNode UI Component. 例如,如果明年我们将WindowsForms交换到Console Application ,则该项目将由于控制台应用程序将没有TreeNode UI组件而被中断。

In this case, is it better to have a domain method which takes for example 5-10 parameters ( int's, strings, etc ) and based on those parameters to create my object or to replaces the parameters with a TreeNode UI Component which ? 在这种情况下,是否最好有一个使用5-10个参数(整数,字符串等)并基于这些参数创建我的对象或用TreeNode UI组件替换这些参数的domain方法?

Thank you in advance. 先感谢您。

@EDIT: @编辑:

I am asking this question, because a colleague of mine reviewed my code and started to refactor it. 我问这个问题是因为我的一位同事检查了我的代码并开始对其进行重构。 By refactoring he was exposing the actual TreeNode UI Component to the Domain-Layer. 通过重构,他将实际的TreeNode UI组件暴露给Domain-Layer。 My approach was AddExplorerNode(string name, string projectName, int projectNumber) etc. 我的方法是AddExplorerNode(字符串名称,字符串projectName,int projectNumber)等。

You can make your own class that acts in a similar way to TreeNode without actually being a TreeNode. 您可以使自己的类以与TreeNode类似的方式运行,而无需实际成为TreeNode。

class TreeNodeModel
{
    public string Name { get; set; }
    public string ProjectName { get; set; }
    public int ProjectNumber { get; set; }
}

Then you can write a method in the UI to map (copy) TreeNodeModel to an actual TreeNode. 然后,您可以在UI中编写一个方法,以将TreeNodeModel映射(复制)到实际的TreeNode。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM