views:

173

answers:

1

Questions

  1. Should the Data Access Layer (DAL) and Business Logic Layer (BLL) be exposed through interfaces or through abstract base classes?
  2. When should we choose abstract classes instead of interfaces and when interfaces instead of abstract classes?
  3. Is one benefit of using abstract base classes that if external party decides to extend/customize the functionality ( of a particular layer) using the base abstract class, then lots of methods exposed by that particular layer would already be implemented in a base abstract class, while with interfaces one would need to implement all the public methods exposed by a particular layer?
+1  A: 

The primary difference is that classes can only inherit from a cingle class, while you can implement many interfaces.

There is a good discussion of the pros and cons here.

1) Typically, these are concrete classes - they may use interfaces/abstract classes to form a consistent framework (a BusinessBase class, a BusinessCommand class, etc), but I'm not sure what you are getting at.

2) Typically use an abstract class when you want to inherit some implementation. Typically an interface when you don't want to restrict the application classes from inheriting from other things.

3) Yes, that's the main benefit, but there are drawbacks due to the single inheritance model.

Cade Roux
1) ROUX - "...but I'm not sure what you are getting at." Let’s assume DAL layer exposes 10 methods, which should be called by BLL when trying to communicate with DAL –-> what I meant to ask is whether it is better that these 10 methods were defined by DAL’s base abstract class or by interface?
carewithl
Typically for BLL, you have base classes you inherit from but they may not always be abstract. For DAL, typically I have some standardized interfaces.
Cade Roux
If I may also ask this - I realize the links you provided are about Interfaces vs Abstract classes, but I thought that in the context of layers, we should decide based on somewhat different arguments and not those mentioned in the links you've provided?!
carewithl
Layering is a logical separation of the system which has to provide some kind of decoupling benefit - having a consistent interface or base class helps, but it is not required - you could simply use a different class and modify until the compiler errors disappeared ;-). Interfaces and abstract classes help facilitate that, but they are simply an implementation tool provided by the language - they help define the interface contract, but that is really only the first step - they can't often go far enough to enforce every behavior you expect/need.
Cade Roux
I really appreciate your help
carewithl