Nested Interfaces in C#.NET

Introduction:

In an object oriented programming, a developer always get confusion about nested interfaces and its implementation. I would like to give a demonstration on this concept with sample example.

Interface with in an Interface like,

  1. publicinterfaceIactions   
  2. {  
  3.     IdataObjectsGetDetails();  
  4. }  
Where IdataObjects is, 
  1. publicinterfaceIdataObjects  
  2. {  
  3.     intempId  
  4.     {  
  5.         get;  
  6.         set;  
  7.     }  
  8.     stringempName  
  9.     {  
  10.         get;  
  11.         set;  
  12.     }  
  13.     stringempAddress  
  14.     {  
  15.         get;  
  16.         set;  
  17.     }  
  18. }  
Find the below screen for solution structure Design,

DESIGN

Implementation:

DataGenerator returns object, whichalways has Data Transfer type objects with help of IdataObjects Interfaces. It is the finest implementation for the nested Interfaces.
  1. classProgram: Iactions  
  2. {    
  3.         publicDataObjects.IdataObjectsGetDetails()  
  4.         {  
  5.             returnnewDataGenerator   
  6.             {  
  7.                 empId = 01,  
  8.                     empName = "maruthi",  
  9.                     empAddress = "Hyderabad"  
  10.             };  
  11.         }  
You can call it with common scenarios.
  1. staticvoid Main(string[] args)   
  2. {  
  3.     ProgramobjProgram = newProgram();  
  4.     varobjData = objProgram.GetDetails();  
  5.     Console.WriteLine(objData.empId.ToString());  
  6.     Console.WriteLine(objData.empName);  
  7.     Console.WriteLine(objData.empAddress);  
  8.     Console.Read();  
  9. }  
Output:

output

 

Next Recommended Reading Nested Namespaces in C#