Vaccano
Vaccano

Reputation: 82437

What are the drawbacks to duplicating a class in different namespaces?

I have a class called SimpleCommand. It is a single file class that implements ICommand in a very simple way (hence the name).

I am finding that I am putting it several of my projects. (I just copy the code and add it into the project.)

These projects are all in the same solution and resulting wpf application.

My question is: Aside from increasing the size of my DLLs by a bit, what are the drawbacks to copying this code around?

(I am trying to decide if it is worth the work to put it in a nuget package.)

NOTE: I have not changed this code in years, and I don't plan to.

Upvotes: 0

Views: 82

Answers (2)

Sten Petrov
Sten Petrov

Reputation: 11040

The issue here isn't that there are various classes with the same name in different namespaces.

The issue is that you're duplicating code, which is really bad idea.

If you want to expand your SimpleCommand to ABitMoreComplexCommand you end up copying it all over.

If you need to compare one command to another by type you couldn't do that reliably - heuristics you may implement could give you false positives

Bottom line: make another project, put all reusable code there, don't copy it around

Upvotes: 3

Fede
Fede

Reputation: 44048

Copying and pasting is the most innefficient way of reusing code, IMO. What happens if you ever decide to add a simple bool property to this class? you will have to do it as many times as you ever copied and pasted it.

I suggest to group these reusable parts in a single DLL and reference them from multiple projects, instead.

Upvotes: 2

Related Questions