Aug 05
2009
Többszörös interface öröklés
Filed Under (Uncategorized) by nameless on 05-08-2009
Töbszörös öröklés interfészekkel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MIInterfaceHierarchy
{
#region interface-k
//az interfészek többszöri öröklése működik
public interface IDrawable
{
void Draw();
}
public interface Iprintable
{
void Print();
void Draw(); // <-- Lehetséges névtükrözés
}
//Többszörös öröklés interészekkel
public interface IShape : IDrawable, Iprintable
{
int GetNumberOfSides();
}
#endregion
#region megvalosito osztalyok
class Rectangle : IShape
{
public int GetNumberOfSides()
{ return 4; }
public void Draw()
{ Console.WriteLine("Drawing..."); }
public void Print()
{ Console.WriteLine("Printing..."); }
}
class Square : IShape
{
void IDrawable.Draw()
{ Console.WriteLine("IDrawable Drawing..."); }
void Iprintable.Draw()
{ Console.WriteLine("Iprintable Drawing..."); }
public void Print()
{ Console.WriteLine("Printing..."); }
public int GetNumberOfSides()
{ return 4; }
}
#endregion
class Program
{
static void Main(string[] args)
{
var myRectangle = new Rectangle();
myRectangle.Draw();
myRectangle.Print();
Console.WriteLine("{0}\n",myRectangle.GetNumberOfSides());
Console.ReadKey();
var mySquare = new Square();
mySquare.Print();
Console.WriteLine(mySquare.GetNumberOfSides());
((IDrawable)mySquare).Draw();
((Iprintable)mySquare).Draw();
Console.ReadKey();
}
}
}
