C# Inheritance – How to Inherit from a Class in a Different DLL

cdesigndll

I need to make an application that needs to be highly modular and that can easily be expanded with new functionality.

I've thought up a design where I have a main window and a list of actions that are implemented using a strategy pattern.

I'd like to implement the base classes/interfaces in a DLL and have the option of loading actions from DLL's which are loaded dynamically when the application starts. This way the main window can initiate actions without having to recompile or redistribute a new version. I just have to (re)distribute new DLL's which I can update dynamically at runtime. This should enable very easy modular updating from a central online source.
The 'action' DLL's all inherit their structure from the code defined in the the DLL which defines the main strategy pattern structure and it's abstract factory.

I'd like to know if C# /.Net will allow such a construction.

I'd also like to know whether this construction has any major problems in terms of design.

Best Answer

Sure, C# will support that. Take a look at this example that uses the System.Collections.Generic.Dictionary as the base class.

public class MyDictionary : Dictionary<string, int> { }

public class MyMain
{
    public MyMain()
    {
        MyDictionary dictionary = new MyDictionary();
        dictionary.Add("hello", 1);
    }
}

There are some potential problems. Any inheriting class will be subject to changes within the base class. So you don't want to use this approach with a base class that is likely to be changing on a frequent basis.

The biggest challenge I have seen is when the base class changes function signatures. That wreaks havoc upon almost all of the inheriting classes.

Related Topic