I had a discussion with friends last week about consuming the classes which are in DLL(.net DLL). I have a .net DLL which I need consume it in my Exe.
Normally,
- I add the DLL in my solution and reference the DLL in my Exe
- Create the object of the Class(which is in my DLL)
- Start calling methods /function in the class from the object just created.
But finally decided that, We should use Reflection not the way we are doing. Reason is Loose coupling. One can change the functionality in the DLL and compile it. In such situations, You don't need to compile client code.
I have a question with this background.
Suppose, I have an a very simple application(Say console application) and I have two classes both are writtern to do different work.
class Program
{
static void Main()
{
//How do you create a object of the class A.
}
}
class A
{
string A = "I am from A";
public B b;
public A
{
b = new B();
}
}
class B
{
string B = "I am from B";
public B
{
}
public void Print()
{
Console.WriteLine(B);
}
}
How do you create the object of Class A when all the three classes the same exe and how you create the same object when Class A and class B in different DLL.
one answer for the sencond part of the question is use interface and use reflection.
Is reflection is it really required, or it is kind of programming standard.
What is the best practice to create an object of the class.