I have two projects; A and B, where B needs to use some classes that are in project A. Hence, I added B to A’s solution, and in B I added a reference to project A.
Is that sensible? Or should I rather put those classes in a class library?
I see that if I further want to open form/program B from a menu option in project A, then A needs a reference to B. Which would not be possible if B already had a reference to A. However if I use the class library for the common classes, then it’s ok as B doesn’t need the A reference.
Does this sound logical? It would be nice to know what are typical reasons for putting projects in the same solution, and if it’s advised to use libraries aggressively to refactor common code between two projects, even if it’s just a couple of classes.. Yet I’ve never made my own library, so a bit unsure on when to use it. If you have some principles would be nice to hear..
Generally, classs libraries are used for common functionality between multiple projects. In other words, exactly what you’re dealing with. So you should pull it out into a class library.
From there, there are two possibilities: if the common functoinality is always going to be the same between the two projects, then it should be a separate project. If it could change for one and not the other then copy it into both projects. You should still refactor it into a class library becasue that will make it easier initially. Note also that in the first case there is going to be another project to be maintained with its own release schedules and management headaches.
Generally, multiple projects in a single solution are a user interface and various libraries and other supporting projects. If there is more than one user interface they are usually realted to the same system, such as a user interface and an admin interface, or possibly interfaces for different platforms.