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,
- publicinterfaceIactions
- {
- IdataObjectsGetDetails();
- }
Where IdataObjects is,
- publicinterfaceIdataObjects
- {
- intempId
- {
- get;
- set;
- }
- stringempName
- {
- get;
- set;
- }
- stringempAddress
- {
- get;
- set;
- }
- }
Find the below screen for solution structure 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.
- classProgram: Iactions
- {
- publicDataObjects.IdataObjectsGetDetails()
- {
- returnnewDataGenerator
- {
- empId = 01,
- empName = "maruthi",
- empAddress = "Hyderabad"
- };
- }
You can call it with common scenarios.
- staticvoid Main(string[] args)
- {
- ProgramobjProgram = newProgram();
- varobjData = objProgram.GetDetails();
- Console.WriteLine(objData.empId.ToString());
- Console.WriteLine(objData.empName);
- Console.WriteLine(objData.empAddress);
- Console.Read();
- }
Output: