When to split code into new assemblies (DLLs)

I work as part of a team building an enterprise application that will be used in the new Windows C # .NET application and its web application. One of the other developers likes to divide things into separate projects a little more than me. His answer is always “divided into all questions,” with which I am not sure I agree.

My theory is that you create separate assemblies when this code can be used by other users. Separation of problems should be performed by namespaces. It can be an extra effort / challenge / nightmare to distribute an application with a lot of builds from version control, obfuscation, etc. Therefore, it concerns me, and I am trying to figure out what the rule is when the code is broken in its own assembly.

What is your rule of thumb for splitting code into other assemblies or using namespaces and other organization methods in an application? Is there any guidance regarding this or patterns / methods that I can read to say “yes, he is right” or “please read this”.

Thanks.

+4
source share
3 answers

I think you have a communication problem or a nomenclature problem, because sharing problems usually means something else.

Strictly speaking, the separation of problems concerns such things as the principle of shared responsibility, in that each class deals with its own domain. In principle, a single responsibility states that a class should have only one reason for the change.

Some examples of problem separation are presentation models and abstraction models, such as MVC or MVVM. Where each component, whether it be a view or a model, concerns an abstraction of the user interface or data and validation, but not both.

Separating code into separate assemblies is good practice when the code can be shared between several projects (for example, you yourself have already indicated). Simple structuring code can be done using different namespaces.

When you have a lot of code, assemblies are a natural way of grouping code, and when you manage code at different levels and have very controlled extensibility points and want to block it, assemblies provide this level of isolation.

+4
source

Partly due to the reasoning already provided by Shark (version control and recompilation / replacement of selected assemblies consumed by a large application). But I also try to create assemblies when this makes the form an independently useful and complete unit of code.

For example, I could create a parsing unit for parsing HTML (this is a crazy order, I know ... this is an example!) For use in a larger application. If the functionality of HTMLParsingUnit is relatively complete (in other words, does not apply to a larger application), then I will most likely create it in my own assembly both for reuse by other code and for encapsulating versions / changes.

Similarly, I once had to create a mapping and provide DataTypes classes from ASNI SQL to the .NET CLR. I created an independent DLL for this, as I thought it might come in handy in other projects. Obviously, this meant that we were talking about detailing the components of the assembly, but it made maintenance easier. Ultimately, I reused this assembly in several different projects.

Just my two cents.,

+3
source

My rule is to always separate code in different code libraries primarily if this DLL can be used by other applications.

But another consideration for me is version control. If the grouping of the code often improves with / scales, it will be easier for me to have this as a separate DLL, so the other DLL / exe in the project are completely unfamiliar with the changes, unless the calls are also changed.

I think these are the two main reasons for splitting code into different DLLs.

+1
source

All Articles