Hi,
During development of my project I have observed a strang behaviour (As per my understanding about OOPS concepts) of interface and class. Below are the details:
I have a DBOperations class impementing 2 interafces IReadOnly and IDML.
class DBOperations : IDML,IReadOnly
{
public string UpdateDB()
{
return "Update Data";
}
public string SelectData()
{
return "Select Data";
}
}
public interface IDML
{
string UpdateDB();
}
public interface IReadOnly
{
string SelectData();
}
The idea is that for select operations I would use IReadOnly interface and for CRUD operations I would use IDML interface.
In my calling class I am able to access
UpdateDB
method from IDML interface from reference of IReadOnly interface !
IReadOnly objIReadOnly = new DBOperations();
IDML objIDML = new DBOperations();
Console.WriteLine(objIReadOnly.SelectData());
Console.WriteLine(objIDML.UpdateDB());
Console.WriteLine(objIReadOnly.GetType().GetMethod("UpdateDB").Invoke(objIReadOnly, null));
Please advise on the behavour.
Thanks in advance !
Regards,
Divya
What I have tried:
Need assistance in understanding the behaviour.