Welcome to weblogs.com.pk Sign in | Join | Help

Using interfaces to pass configurations through tiers

Most of the application needs set of configuration to work smoothly, e.g. database connection string. I am a big fan of using interfaces, one of the biggest advantages it of using them with modern compiler is that you will not be able to compile your code unless complete implementation of interface is provided. And this increase confidence and eventually less runtime errors.

Here is one approach of implementing an approach for passing configurations from user interface to library, considering that we want to test the library even in absence of user interface implementation.

  1. Define an interface for all the required parameters, lets call it IConfig
  2. Code an implementation of this interface in the user interface
  3. Code an implementation of this interface in your unit test library
  4. The interface will be a parameter for GetInstance methods in the central factory. For discussion around using central factory please read my previous posts. Implementing Security Part 1 and Part 2

Here are relevant portions of the approach I suggested to my colleague to use.

The IConfig

IConfig implementation in user interface

GetInstance method of central factory

User interface using the controller to perform the required action

Published Monday, September 12, 2005 2:16 PM by khurram
Filed under: ,


No Comments

New Comments to this post are disabled