2016-11-18 44 views
0

的方法我们已经成功地完成开发新的Web应用程序。它有表示层,业务层&数据访问层。最佳中间层和转换功能

新的Web应用程序,我们移植现有的业务层&数据访问层只表示层将被改变。

尽管我们要使用相同的业务层,但会出现可能存在不同模型而非现有模型的情况。

我们计划建立中间层(新型号)和转换功能,从现有的业务层提供的模型产生新的模式。

namespace Busniess 
{ 
    public class Employee 
    { 
     public string FirstName {get; set;} 
     public string LastName {get; set;} 
    } 
} 

新的中间层,

 namespace Intermediate 
    { 
     public class Employee 
     { 
      public string Address {get; set;} 
      public string Zip {get; set;} 
     } 
    } 

当我创建员工的情况下,Employee对象应该能够转化成下面的场景

1. GetAll (all the properties FirstName, LastName, Address & Zip) 
2. Selected (FirstName & Address) - if possible controlled through attribute decoration. 

什么是创造最好的办法中间层&转换函数?

如果中间层&转换函数不是一个好候选,那么最好的方法是什么?

+0

这是扩展现有模型类的基本继承。 – niksofteng

回答

0

根据理解,您以后的中间层仅仅是一个带有附加扩展/属性的实际业务层的调用。其中一种方法是从Business对象继承到中间层。通过这种方式,您将可以访问业务层的所有功能整合到中间层代码将符合DRY原则。

namespace Intermediate 
{ 
    public class Employee : Busniess.Employee 
    { 
     public Employee() : base() { } 
     public string Address { get; set; } 
     public string Zip { get; set; } 
    } 
}