Combining Duplicate Classses From different Libs that are the same class

73 Views Asked by At

I was wondering if someone could help me.

I Have a n-tier application and each layer is a class lib. DAL -> BLL -> PL Data Access Layer -> Business Logic Layer -> Presentation Layer

In my PL i Need to reference my wrapper class "Shippers" from the DAL however i want to remove the dependency to my DAL and make it go through my BLL. This forces me to have a duplicate class of my shippers in my BLL.

However How would i link two of the same classes in 2 different Libs? I also have no clue of what the term of duplicating the same classes is known as?

Here is my Shippers Class

public class Shippers
{

    public int ShipperID { get; set; }
    public string CompanyName { get; set; }
    public string Phone { get; set; }
}
3

There are 3 best solutions below

2
On BEST ANSWER

In that case, use Composition technique and in your BLL project add the dll reference of the library which contains Shippers class. Bll class have the Shipper as member field and expose a public property/method which returns a instance of Shipper and access the same from your PL DAL. Like below:

BLL Project

public class BLL_Some_Class
{
  private Shipper _shipper = new Shipper();

  public Shipper getShipper
     {
       get{ return _shipper; }
      } 
} 

PL DAL Project

BLL_Some_Class bll1 = new BLL_Some_Class();
bll1.getShipper;
3
On

What you can do is create a class on BLL and make it inherit from Shippers on DAL, would look something like this in your BLL:

public class Shippers:DAL.Shippers
{
}
0
On

So finally i found a solution it was to make a central class lib holding the shipper class. I then used this as a reference to all the PLL and DAL and BL and this would remove the dependency to my DAL from the PLL

Thanks for all the help