如何在各层之间处理业务对象 [英] how to handle the business object among the layers

查看:59
本文介绍了如何在各层之间处理业务对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我的应用程序中包含以下几层.

1)业务对象层:一个仅保留实体定义的独立项目
2)数据访问层:对对象的原始操作
3)业务层:对象操作(保存,删除,更新,插入)
4)服务层:公开对象的服务
5)客户端:使用服务.

我的问题是如何在各层之间维护业务对象.我想遍历各层之间的对象.但是我不知道该如何实现.

假设我在业务对象层中有一个产品对象,现在我想要以下内容.

1)如何通过服务层公开此对象,我是否必须在服务层以及客户端复制产品对象?


这是供您查看的示例代码.


业务对象层:

Hi friends

I am having the following layers in my application.

1) Business Objects Layer: a separate project that keeps only entity definitions
2) Data Access Layer : Crud operations on objects
3) Business Layer : object operations (Save,Delete,Update,insert)
4) Service Layer : Exposing the service for Objects
5) Client : Consuming the services.

My question is that how I can maintain the Business Objects among the layers. I want to traverse the object between the layers. But I don’t know exactly how to implement this.

Suppose I have a Product Object in business object layer,Now I want the following.

1)How to expose this object with the Service layer, will I have to duplicate the product object in service layer as well as at the client side?


Here is the sample code for your review.


Business Objects Layer :

Public class Product
{
Private string Name;
Private string Code ;
…
}



业务层:



Business Layer :

Public bool Save(Product objProduct)
{
…
}



数据访问层:



Data Access Layer :

Public bool Save(Product objProduct)
{
…
}


服务层


Service Layer

[ServiceContract]
 public interface IProduct
    {
        [OperationContract]
        save(product objproduct);
         }

public class product : IProduct
    {
        Public void save(product objproduct);
         }



客户:




Client :


ProductService ProductClient = new ProductService();
ProductClient.open();
Product  p = new product();
p.name="abc";
p.code="001";
ProductClient.save(P);
ProductClient.Close();




请指导我.

非常感谢!!




Please guide me.

Many appreciations !!

推荐答案

好吧,我不知道这些层是否是分离的程序集(或项目).

如果它们是分开的程序集,那么最好将客户对象作为共享类,则可以使用此类在这些层之间传递数据,如果所有层都在一个项目中,那么可以在另一个层中调用它们就没问题了.
简单来说:


bussinessObject.addDataToDB(Customer cusObj)
{
dataAccessLayer.insert(cusobj);
}
ok, i don''t know whether these layers are separated assemblies (or projects) or not .

if they are separated assemblies then better to have the customer object as a shared class, then you can use this class to pass data between these layers, if all the layers are in one project it not problem you can call them one with in another .
for easmple:


bussinessObject.addDataToDB(Customer cusObj)
{
dataAccessLayer.insert(cusobj);
}


创建一组值对象(属性+其getter设置器)-每个值对象代表您需要传递的对象.

然后,您可以在这些图层之间传递这些值对象.
Create a set of value objects (properties + their getter setters) - each value object representing an object you need to pass around.

You can then pass these value objects across these layers.


这篇关于如何在各层之间处理业务对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆