tags:

views:

20

answers:

1

I am designing a .Net library that exposes methods all of which can be tagged only as helper methods. Takes in PersonID, RoleID etc returns calculated salary, Salary for the entire year, Bonus etc.

  • Is it ok to design just a static class that has methods like GetSalary(), GetBonus(), GetHistoricSalary().
  • Or should I have an interface ISalaryProcessor and have these methods in there ?

With option 2 the implementing class just has behaviour and not data, in trying to bring in a contract am I creating a unwanted pure fabrication ?

+1  A: 

If you supply an interface (or several interfaces, as per ISP), your clients can provide their own implementations for parts of your library and easily switch it if needed (for example for testing purposes).

It also allows clients to program to an interface and follow LSP in their program, making the implementation decoupled from their application.

For such flexibility, I would go with interfaces.

With a static library, there is no way to switch it out and a direct dependency is introduced (against LSP).

Oded
Agreed. But my SalaryProcessor that implementes ISalaryProcessor will have only behaviour, is it ok for a class to have just behaviour ?
anivas
@anivas - If it's just a helper class, then why not? Be practical, not dogmatic.
Oded