Tuesday, February 16, 2010

Playing with simple Interface Concept

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program:interface_first ,interface_second
{

public static void Main()
{
Console.WriteLine("INTERFACE TEST\n");

//call by class objects.
Program call_interface_first = new Program();
call_interface_first.method_for_interface("Invoke first interface method using object of first class");
call_interface_first.methos_for_second_interface("Invoke second interface method using object of first class\n");

second_calss call_interface_second = new second_calss();
call_interface_second.method_for_interface("Invoke first interface method using object of second class\n");



interface_first first_interface_call = call_interface_first;
first_interface_call.method_for_interface("Call the first interface using interface object with assing class objects");
interface_second second_interface_call = call_interface_first;
second_interface_call.methos_for_second_interface("Call the second interface using interface object with assing class objects\n");

//call by same interface objects.
interface_first call_using_interface_refference = new Program();
call_using_interface_refference.method_for_interface("call first interface using the same interface reference");
interface_first call_using_interface_refference1 = new second_calss();
call_using_interface_refference1.method_for_interface("call second interface using the same interface reference\n");

//call by interface array with same reference.
interface_first[] array_interface = { new Program(), new second_calss() };
for (int i = 0; i <= 1; i++)
{
array_interface[i].method_for_interface("Invoke interface methods from class in array format :" + i);

}

}

public string method_for_interface(string i)
{

Console.WriteLine(i.ToString());
return i;
}
public string methos_for_second_interface(string s)
{
Console.WriteLine(s.ToString());
return s;
}

}

interface interface_first
{
//void interface_method_first();
string method_for_interface(string i);

}
interface interface_second
{
string methos_for_second_interface(string s);
}

//second class for accessing Interface
class second_calss : interface_first
{
public string method_for_interface(string s)
{
Console.WriteLine(s.ToString());
return s;
}
}
}

No comments: