tags:

views:

58

answers:

1

If I have two assemblies, one containing just business rules (assembly A), and the other that acts as an interface to external dependencies such as File system, DBs, web services, etc. (assembly B), should A reference B or should B reference A?

For Example:

If I have a SourceCodeInterpreter class (assembly A), should it instantiate a SourceCodeFileReader (in assembly B) to read in the data, or should the SourceCodeFileReader instantiate a SourceCodeInterpreter class after reading the source file and then start the interpreter?

+1  A: 

It all depends on how things are going to be used. If an assembly uses a type defined in another assembly, it will need a reference to it. I try to avoid adding dependencies between assemblies unless they really have a reason for existing.

In your example, I'd try to leave the two assemblies separate. Both of these assemblies are most likely being used by your application. Your application can reference both, and they can be independant. The app would use SourceCodeFileReader to read in your code, then pass it to your SourceCodeInterpreter to interpret it.

If, however, you're trying to make this require a single type to be used, I'd put the "top level" assembly as the one containing a reference to the "lower level details". In this case, that would probably mean having the interpreter reference the reader - since a reader is lower level, and useless on its own.

Reed Copsey
I like this one. I had it in my head that to keep the main app as dumb and simple as possible it had to invoke a single method on a single class, but it's not that much more to use two classes/assemblies. Much better separation of concerns this way. Thanks!
Doug Seelinger