Last post Dec 12, 2010 11:55 AM by talktodale
Dec 03, 2010 08:59 AM|talktodale|LINK
I am looking for general direction on the best practice here. I have a class that I want to share between two different forms in two projects that are associated. The two forms are in seperate projects but both projects load together as I have added the
second project to the first. I also have a class that I want to share between these two projects which will cause me to add another project to this solution with will mean I will have three projects in my solution. My question is how do I best share this
I believe the only way to do this is to add the class in the reference in both of the form projects?... Is this correct ? I'd really like to just reference the class and inherit it in the source code without adding it
as a reference but I am feeling that I can't do that. I am obviously pressed for time and working on other projects and a I am a experienced coder with only about 1 year of C# experience... Thanks Guys ! Dale n Orlando
c # class object inheritance
Dec 03, 2010 09:48 AM|Spikeh|LINK
If the class is a finished class (i.e. you have no more work to do on it), then you can compile it in to its own assembly and either copy + reference it in your projects, or add it to the GAC (Global Assembly Cache) and reference it from there. I would only
recommend the GAC if you're going to be using the class in a lot of projects, though it's overkill if it's only in a few.
IF your class is unfinished (or you just simply want to be able to easily debug and edit it), you can just add the additional project to your solution, reference it and have it compile with the other projects. Be aware that any changes to this class affect
both of your other projects, so it should be as generic as possible and you shouldn't mess about with member signatures unless you're willing to change them in all the other projects. This is where version control comes in handy...
I've written about solutions, projects, namespaces and assemblies on my blog recently, if it's any use to you:
It's aimed at an nTier approach, but the lessons still ring true in other scenarios.
Dec 03, 2010 10:55 AM|talktodale|LINK
This is very clear and I appreciate your guidance. I will also read your blog post on solutions, projects, namespaces and assemblies. Thank you !
Switching from procedural programming languages (my first language was Clipper Summer 87) to Object Oriented Languages was definately the
biggest challenge in my career but I'm almost there. I've come so far but I'm always wondering if I am doing it right, with no one else to review my systems.
Dale n Orlando
Dec 08, 2010 08:12 AM|Spikeh|LINK
Yes, it's a big step... I moved from VBScript (Classic ASP) to VB.Net, then in to C#.Net. That was the easy part... the hard part was learning the benefit of object orientation and architectural & design patterns. Once the penny drops, though, you fly :)
Hope it came in useful :) Rep would be nice ;)
Dec 12, 2010 11:55 AM|talktodale|LINK
Sorry for the late reply. I was on vacation . As far as whether it worked or not, it absolutely did. I had some basic knowlege of this concept but your explanation made it even more clear and helped me clarify the way to do it. I compiled the Library code
in a separate project and now two other projects are sharing the Library code as a reference and instantiating the objects. Thanks for your help ! Dale