将BLL类标记为静态或?

时间:2012-01-05 14:45:17

标签: static-methods data-access bll

我已经有了分层数据访问设计,效果很好。但我不知道它是否是最合适的实施方式 我只是想知道BLL类或methots应该是静态的,还是应该是只有一个实例的concreate类? 与此同时,我不需要序列化BLL类以在这样的SOA设计中使用它。但我不知道这个功能会带来什么 请查看以下选项:

  1. BLL课程和methots是静态的
  2. BLL类不是静态的,但它的methots是静态的
  3. BLL课程不是静态的,也不是它的标准。应用程序应每次创建BLL类以访问其methot。
  4. BLL课程不是静态的,也不是它的标准。但是每个BLL类只有一个实例。并且应用程序使用这些静态实例以便使用BLL methots。
  5. 哪一个最有效率的表现和设计?

    编辑:

    选项1

    public static class BllCustomer
    {
        public static List<ModelCustomer> GetCustomers()
        {
    
        }
    }
    
    // usage
    BllCustomer.GetCustomers();
    

    选项2

    public class BllCustomer
    {
        public static List<ModelCustomer> GetCustomers()
        {
    
        }
    }
    
    // usage
    BllCustomer.GetCustomers();
    

    选项3

    public class BllCustomer
    {
        public List<ModelCustomer> GetCustomers()
        {
    
        }
    }
    
    // usage
    BllCustomer bllCustomer = new BllCustomer();
    bllCustomer.GetCustomers();
    

    选项4

    public class BllCustomer
    {
        public List<ModelCustomer> GetCustomer()
        {
    
        }
    }
    
    // usage
    public static BllCustomer s_BllCustomer = new BllCustomer();
    // whenever needed
    s_BllCustomer.GetCustomer();
    

2 个答案:

答案 0 :(得分:1)

序列化您的域/ BusinessLogicLayer类听起来有点不寻常,因为您的域层通常包含业务规则和复杂的处理逻辑。通常,您需要序列化DataTransformation / POCO类。

静态或具体类/方法之间存在边际performance差异。我会回避主要业务逻辑的静态类和方法,因为它们很难进行模拟/单元测试,而且不能使用IoC容器。所以考虑到这一点,我会推荐选项3,因为你已经解释过了。还发布了一些非常有用的答案here

答案 1 :(得分:0)

对于性能和易用性,选项二最有意义。我现在使用选项2并没有遇到任何问题。它们中的大多数只包含一行调用DAL,然后另一行调用log4net。他们中的大多数人都没有很多商业逻辑。

然而,我在ASP.NET中使用它。