Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 !!
Posted
Updated 15-Jun-10 22:49pm
v2

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);
}
 
Share this answer
 
Comments
rajeshswami27 16-Jun-10 5:25am    
Thanks prasadbuddhika for your quick reply

These are sperate projects. I have refered the Business Objects assembly to the service layer. but how I expose the product object to the client. Do I have to decorate the class with DataContract,DataMember in the business object assembly or I have to duplicate this class in the service layar.

how I will acess the product object at the client side.


if you could give me an example it will be highly appreciated.

Thanks.
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900