Reasons to split project into multiple projects?
Asked Answered
F

8

14

What are common reasons to split a development project (e.g. ASP.NET MVC application) into multiple projects? Code organization can be done via folders just as well. Multiple projects tend to generate circular reference conflicts and increase complexity by having to manage/resolve those.

So, why?

Forestforestage answered 24/8, 2009 at 4:44 Comment(0)
S
10

Some reasons are

Encapsulation - By packaging a set of routines into another library, either as a static library or a set of dlls, it becomes a black box. For it to be a good black box, all you need to do is to make sure you give the right inputs and get the right outputs. It helps when you re-use that library. It also enforces certain rules and prevent programming by hacks ('hmm...I'll just make that member function public for now')

Reduces compile time - the library is already complied; you don't have to rebuild it at compile time, just link to it (assuming you are doing C++).

Decoupling - By encasing your classes into a standalone libraries, you can reduce coupling and allows you to reuse the library for other purpose. Likewise, as long as the interface of the library does not change, you can make changes to the library all you like, and others who link to it or refer to it does not need to change their code at all. DLLs are useful in this aspect that no re-compilation is required, but can be tricky to work with if many applications install different versions of the same DLLs. You can update libraries without impacting the client's code. While you can do the same with just folders, there is no explicit mechanism to force this behaviour.

Also, by practicing this discipline of having different libraries, you can also make sure what you have written is generic and decoupled from implementation.

Licensing/Commercialization - Well, I think this is quite obvious.

Senegambia answered 24/8, 2009 at 5:17 Comment(0)
L
3

One possibility is to have a system that a given group (or single developer) can work on independently of the rest of the code. Another is to factor out common utility code that the rest of the system needs -- things like error handling, logging, and common utilities come to mind.

Of course, just when thinking about what goes in a particular function / class / file, where the boundaries are is a matter of art, not science.

Lonesome answered 24/8, 2009 at 4:54 Comment(0)
P
1

One example I can think of is that you might find in developing one project that you end up developing a library which may be of more general use and which deserves to be its own project. For instance maybe you're working on a video game, and you end up writing an audio library that's in no way tied specifically to the game project.

Paloma answered 24/8, 2009 at 4:56 Comment(0)
S
1
  1. Code reuse. Let's say you have project A and you start a new project B which has many of the same functions as project A. It makes sense to pull out the shared parts of A and make them into a library which can be used by both A and B. This allows you to have the code in both without having to maintain the same code in two places.

  2. Code reuse, inverted. Let's say you have a project which works on one platform. Now you want it to work on two platforms. If you can separate out the platform-dependent code, you can start different projects for each platform-dependent library and then compile your central codebase with different libraries for different platforms.

Staffman answered 24/8, 2009 at 5:43 Comment(0)
W
1

Some tips about split your project into multiple projects:

One reason for separating a project into multiple class libraries is re-usability. I’ve yet to see the BLL or DAL part of application re-used in another application. This is what textbooks from the 90s used to tell us! But most if not all modern applications are too specific and even in the same enterprise, I’ve never seen the same BLL or DAL parts re-used across multiple applications. Most of the time what you have in those class libraries is purely to serve what the user sees in that particular application, and it’s not something that can be easily re-used (if at all).

Another reason for separating a project into multiple class libraries is about deployability. If you want to independently version and deploy these pieces, it does make sense to go down this path. But this is often a use case for frameworks, not enterprise applications. Entity Framework is a good example. It’s composed of multiple assemblies each focusing on different areas of functionality. We have one core assembly which includes the main artifacts, we have another assembly for talking to a SQL Server database, another one for SQLite and so on. With this modular architecture, we can reference and download only the parts that we need.

Imagine if Entity Framework was only one assembly! It would be one gigantic assembly with lots of code that we won’t need. Also, every time the support team added a new feature or fixed a bug, the entire monolithic assembly would have to be compiled and deployed. This would make this assembly very fragile. If we’re using Entity Framework on top of SQL Server, why should an upgrade because of a bug fix for SQLite impact our application? It shouldn’t! That’s why it’s designed in a modular way.

In most web applications out there, we version and deploy all these assemblies (Web, BLL and DAL) together. So, separating a project into 3 projects do not add any values.

Layers are conceptual. They don’t have a physical representation in code. Having a folder or an assembly called BLL or DAL doesn’t mean you have properly layered your application, neither does it mean you have improved maintainability. Maintainability is about clean code, small methods, small classes each having a single responsibility and limited coupling between these classes. Splitting a project with fat classes and fat methods into BLL/DAL projects doesn’t improve the maintainability of your software. Assemblies are units of versioning and deployment. Split a project into multiple projects if you want to re-use certain parts of that in other projects, or if you want to independently version and deploy each project.

Source: https://programmingwithmosh.com/csharp/should-you-split-your-asp-net-mvc-project-into-multiple-projects/

Whomsoever answered 12/10, 2018 at 2:57 Comment(0)
U
0

Ownership for one thing. If you have developers responsible for different parts of the code base then splitting the project up is the natural thing to do. One would also split projects by functionality. This reduces conflicts and complexity. If it increases, that just means a lack of communication and you are just doing it wrong.

Uglify answered 24/8, 2009 at 4:54 Comment(1)
This makes code ownership more exclusive, which I think is a bad thing. Exclusive code ownership requires more communication (as you noted) and communication is always difficult to get. It also requires more cooperation (if I need your code changed, it's now much harder to do it myself) which is also difficult to get. In this scenario, one bad team player can f*** things up for everyone.Staffman
U
0

Instead of questioning the value of code in multiple assemblies, question the value of clumping all of your code in one place.

Would you put everything in your kitchen in a single cabinet?

Circular references are circular references, whether they happen between assemblies or within them. The design of the offending components is most likely sub-optimal; eschewing organization via assemblies ironically prevents the compiler from detecting the situation for you.

I don't understand the statement that you can organize code just as well with folders as with projects. If that were true, our operating systems wouldn't have the concept of separate drives; they would just have one giant folder structure. Higher-order organizational patterns express a different kind of intent than simple folders.

Projects say "These concepts are closely related, and only peripherally related to other concepts."

Unfriendly answered 24/8, 2009 at 5:45 Comment(2)
You are right; I'm just encountering lots of circular references (described in this question: #1321061) which seem to make separation of projects extremely tedious, or I am making some huge design mistakes which I'm not aware of (and would like to learn from).Forestforestage
Added an answer to the linked question.Unfriendly
C
0

There are some good answers here so I'll try not to repeat.

One benefit of splitting code out to it's own project is to reuse the assembly across multiple applications.

I liked the functional approach mentioned as well (e.g. Inventory, Shipping, etc. could all get their own projects). Another idea is to consider the deployment model. Code shared between layers, tiers, or servers should probably be in it's own common project (or set of projects if finer control is desired). Code earmarked for a certain tier may be in it's own project. e.g. if you had a separate web server and application server then you wouldn't want to deploy the UI code on the application server.

Another reason to split may be to allow small incremental deploys once the application is in production. Let's say you get an emergency production bug that needs to be fixed. If the small change requires a rebuild of the entire (one project) application you might have a hard time justifying a small test cycle to QA. You might have an easier sell if you were deploying only one assembly with a smaller set of functionality.

Cell answered 24/8, 2009 at 7:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.