top of page
Search
  • Writer's pictureDon Richardson

One object Multiple implementations

So, I need to be able to execute a specific interface implementation based on the interface being used on the newly instantiated object.

This would allow us to change the implementation by changing the interface.

Probably standard stuff but here's my code to get it working;

Example:

Interface Definition:

public interface IThisInterface

{

void DoAThing();

}

public interface IThatInterface

{

void DoAThing();

}

Class Definition:

public class ThisClass : IThisInterface, IThatInterface

{

void IThisInterface.DoAThing()

{

MessageBox.Show("Do THIS thing");

}

void IThatInterface.DoAThing()

{

MessageBox.Show("Do THAT thing");

}

}

Execution:

IThisInterface thisClass = new ThisClass();

thisClass.DoAThing();

//Executes the DoAThing method on the IThisInterface

IThatInterface thatClass = new ThisClass();

thatClass.DoAThing();

//Executes the DoAThing method on the IThatInterface

10 views0 comments

Recent Posts

See All

System.Net.Http v4.2.0.0 not loading

So.. it turns out that the incorrect dll is loaded via nuget. As a work-around, redirect your manifest to look for 4.0.0.0 and it works. Add this to your runtime dependency list in the config. <depend

SSRS in Visual Studio 2019 and GIT

One of the problems with BIDS is that it wont allow you to have folders and subfolders. You can have a project for each folder which will the do the trick for single level hierarchies. You can create

bottom of page