Armen Tsirunyan
Armen Tsirunyan

Reputation: 132974

Making each class a separate assembly

I am not an experienced .Net programmer, hence this question.

Is it a terribly bad idea to put each (major) class in a separate assembly, so that whichever class's implementation I choose to change the executable need not be recompiled? Or does my idea imply serious performance issues due to runtime loading etc.?

I know the question is vague, but maybe there are specific guidelines as to what should be put in a separate assembly and what genereally shouldn't

Thanks in advance

Upvotes: 3

Views: 1547

Answers (5)

Mert Susur
Mert Susur

Reputation: 583

If all of these classes you are talking about are doing different jobs and also can be seperated by the business they are doing then, putting each of them to seperate assembly is acceptable I suppose. However you also should be careful about this issue, else your applications might turn into a DLL hell!

Upvotes: 0

Hanan
Hanan

Reputation: 1445

It is a very bad idea.

  • It will not save you compile-time.
  • It will cost you run time.
  • It will complicate your development and spend you a lot of your time.
  • It will lead to bugs.
  • Other mechanisms in the C# compiler take care of saving compile-time if you only change 1 file (by the way one class per file is the standard - but there are some exceptions)

You need to put things in separate assemblies if you plan to redistribute them (install them to your end-users) as separate components. I'll bet that is not your scenario.

examples where you might split to assemblies:

  • two entirely different programs - clock.exe and facebookAlbumViewer.exe
  • 3-tier software: MyProgramDataModel.dll, MyProgramBusinessLogic.dll and MyProgramGui.exe in the future you ship a new MyProgramDataModel.dll (that now works with Oracle instead of MySql), so you deploy only that component. It will only make sense on big and complicated software.

Upvotes: 4

Kieren Johnstone
Kieren Johnstone

Reputation: 41983

You talk about client software. A decent-sized project with a few hundred classes -> a few hundred DLLs is not acceptable for client software and this is not common practice.

Assemblies just aren't that big to worry about it. With a DLL per class you'll be exposing all of your code structure - MyApp.dll, MyApp.MainForm.dll, MyApp.DatabaseLogic.UserAuthentication.dll -

Upvotes: 4

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174289

It's not a good idea. Put concerns together in one assembly. But not a single class per assembly. If you change two classes, you need to ship two assemblies instead of one. What have you won?

Upvotes: 5

Snowbear
Snowbear

Reputation: 17274

How much time will you save on compilation? How much time will you spend on adding a new project for each class?

Do not waste your time, let compiler do his job. Your time worth more than compiler's.

Upvotes: 2

Related Questions