0

I am new to C# and want some help regarding some small task.

I have two projects (Project1 and Project2) which are dependent on each other. I would like to call the methods from Project1 which is used as reference in Project2 without creating object of Project1. This means that I don't want to use Project1 directly because if I do so and some changes are made in Project1 I will have to recompile Project2 as well.

Can we create any intermediate project (say Project3) which will work as bridge between this two projects? So that Project3 can be used in some other task if needed. If this is possible then please let me know how?

I have stuck due to this.

bravo
  • 1
  • 3
  • 3
    You don't always need to recompile a program when a dll is rebuilt, there are [breaking changes and non-breaking changes](http://stackoverflow.com/questions/1456785/a-definitive-guide-to-api-breaking-changes-in-net). Anyway, if the methods you need to call are instance methods, then you need to instance an object – Matteo Umili Oct 21 '15 at 07:34
  • add some code or diagram because so far your problem is impossible to understand, from what you have said so far, no you do not need to recompile project 2 unless you change its interfaces, and if so who cares? – mikus Oct 21 '15 at 07:46
  • Thanks for the reply. But I would like to create some interface between Project1 and Project2 so that I can utilise that interface in some other project as well. Is this possible? – bravo Oct 21 '15 at 07:47
  • well sure, but so far its still hard to understand what you want to achieve, put some code – mikus Oct 21 '15 at 07:49
  • Sorry @mikus , as of now I don't have any code. As of now I have just some idea but don't know whether it works or not. I am thinking of creating some interface which will access the methods of dll of Project1 and Project2 will access this interface. Don't know how much correct this idea is. – bravo Oct 21 '15 at 07:56
  • more or less adapter design pattern? :) if you dont have code, draw a diagram, very likely it will answer your question already – mikus Oct 21 '15 at 08:09
  • Exactly @mikus. I am also thinking of adapter design pattern. But I thought it will throw some exception because it doesn't have object initialised for the interface class. Can you please explain me with some code how to access it?? I am really confused with it.]\ – bravo Oct 21 '15 at 08:18
  • I dont think you quite understand how it works, please read the code examples at wikipedia. What adapter does it allows you to have a different, potentially easier or more generic interface to existing types. You do need to instantiate Project one type or use its static methods. Adapter class/project is just a consumer of Project 1 services as any other, only providing more / better functionality / abstraction level. No idea what is your fear about creating instances of Project1 types anyway. – mikus Oct 21 '15 at 08:33
  • To be clear, you make an instance of Project1 type in Project3, and then Project2 creates an instance of Project3, so Project 2 doesn't know about project1, thaat's the benefit. – mikus Oct 21 '15 at 08:41
  • Okay. Thank you very much. – bravo Oct 21 '15 at 08:52

0 Answers0