0

我有一个跨层传输的业务层对象,Widget。我希望它在不同的层中公开一组不同的属性。以下是编译器读取注释时的样子:

//bl.dll

public abstract class Widget
{
    //repo only
    internal virtual Ppty_A {get;set;} //internal to implementation assembly of repo

    //repo and service only
    internal virtual Ppty_B {get;set;} //internal to implementation assemblies of repo/svc

    //everyone inlcuding presentation
    public virtual Ppty_C {get;set;} 
}
public interface IWidgetService
{ ... }    }
public interface IWidgetRepo
{ ... }
public class SimpleWidgetService : IWidgetService
{ ... }

//dal.dll
using bl;
public WidgetRepo
{ ... }

//presentation.dll
using bl;
public WidgetController
{
    public WidgetController(IWidgetService ...)
    ...
}

我的想法是这样做(我还没有测试过,它只解决了一半的问题):

//bl.dll
public abstract class Widget
{
    //repo only simply can't be defined in the abstraction -- can't see you => no contract

    //repo and service only has to be public?
    public virtual Ppty_B {get;set;}

    //at least public is public...
    public virtual Ppty_C {get;set;} 
}

//dal.dll
using bl;
public SQLWidget : Widget //Or actually DALBLWidget -- see below?
{ 
    //repo only
    internal ...
    internal ...

    //the rest
    ...
}

我应该只创建另一个抽象小部件(有一个 DAL-BL 小部件和一个 BL-UI 小部件)吗?

4

1 回答 1

1

您可以让 Widget 类实现对应于每一层的不同接口。

public class Widget : IDataLayerWidget, IBusinessLayerWidget
{
 // Properties
}

public interface IDataLayerWidget
{
   // Properties visible to the DataLayer
}

public interface IBusinessLayerWidget
{
   // Properties visible to the BusinessLayer
}

在您的 DataLayer 中,您将使用IDataLayerWidget和 在您的业务层中使用IBusinessLayerWidget.

于 2012-04-15T19:29:20.000 回答