Home > Software design >  Inherit from Interface only if dll is available
Inherit from Interface only if dll is available

Time:10-15

I have a class that is supposed to inherit from an interface only if the *.dll-file of the interface is available.

Example:

"commandInterface.dll" contains following interface:

public interface ICommand
{
    string GetName();
    string Run(string[] args);
}

"main.exe" contains following class:

public class TestCommand : ICommand
{
    public string GetName()
    {
        return "test";
    }
    
    public string Run(string[] args)
    {
        return args[0];
    }
}

That works if both files are in the same directory. Is there any way to run "main.exe" even if "commandInterface.dll" is missing? So that the class is still there, only that it no longer inherits from the interface?

CodePudding user response:

No. If the interface is missing, this won't work.

  • Related