Interfaces and abstract class:
InterFace project 1:
using System;
using System.Collections.Generic;
using System.Text;
namespace InterFacesProject
{
public interface ISortable
{
void SortData();
bool IsSorted
{
get;
}
}
}
Interface project 2:
using System;
using System.Collections.Generic;
using System.Text;
namespace InterFaceImplementation2
{
public interface ISortable2
{
void SortData1();
bool IsSorted1
{
get;
}
}
}
Abstract class project one :
using System;
using System.Collections.Generic;
using System.Text;
namespace OopsImplenation
{
using System;
public abstract class Shape
{
private float _area;
private System.Drawing.Color _color;
private float _perimeter;
public float Area
{
get
{
return _area;
}
set
{
_area = value;
}
}
public System.Drawing.Color Color
{
get
{
return _color;
}
set
{
_color = value;
}
}
public float Perimeter
{
get
{
return _perimeter;
}
set
{
_perimeter = value;
}
}
public abstract void CalculateArea();
public abstract void CalculatePerimeter();
}
}
Abstract class implementation two:
using System;
using System.Collections.Generic;
using System.Text;
using OopsImplenation;
using InterFacesProject;
using InterFaceImplementation2;
using OopsImplentation2;
namespace buinesslayer
{
public class Class1 : OopsImplenation.Shape, InterFacesProject.ISortable, InterFaceImplementation2.ISortable2
{
public int check1()
{
return 1;
}
public int check2()
{
return 2;
}
public override void CalculateArea()
{
throw new Exception("The method or operation is not implemented.");
}
public override void CalculatePerimeter()
{
throw new Exception("The method or operation is not implemented.");
}
#region ISortable2 Members
public bool IsSorted1
{
get { throw new Exception("The method or operation is not implemented."); }
}
public void SortData1()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region ISortable2 Members
bool ISortable2.IsSorted1
{
get { throw new Exception("The method or operation is not implemented."); }
}
void ISortable2.SortData1()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region ISortable Members
public bool IsSorted
{
get { throw new Exception("The method or operation is not implemented."); }
}
public void SortData()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region ISortable Members
bool ISortable.IsSorted
{
get { throw new Exception("The method or operation is not implemented."); }
}
void ISortable.SortData()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
}
Businesslayer: [ added the references of all interfaces and abbstract classes]
using System;
using System.Collections.Generic;
using System.Text;
using OopsImplenation;
using InterFacesProject;
using InterFaceImplementation2;
using OopsImplentation2;
namespace buinesslayer
{
public class Class1 : OopsImplenation.Shape, InterFacesProject.ISortable, InterFaceImplementation2.ISortable2
{
public int check1()
{
return 1;
}
public int check2()
{
return 2;
}
public override void CalculateArea()
{
throw new Exception("The method or operation is not implemented.");
}
public override void CalculatePerimeter()
{
throw new Exception("The method or operation is not implemented.");
}
#region ISortable2 Members
public bool IsSorted1
{
get { throw new Exception("The method or operation is not implemented."); }
}
public void SortData1()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region ISortable2 Members
bool ISortable2.IsSorted1
{
get { throw new Exception("The method or operation is not implemented."); }
}
void ISortable2.SortData1()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region ISortable Members
public bool IsSorted
{
get { throw new Exception("The method or operation is not implemented."); }
}
public void SortData()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region ISortable Members
bool ISortable.IsSorted
{
get { throw new Exception("The method or operation is not implemented."); }
}
void ISortable.SortData()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
}
Observations:
/- Can not implement multiple abstract classes.
/- Can implement multiple interfaces with conflicts as well but with two mechanisams
implicit implemention [public] and explicit implicit implimention [ no public]
/-interfaces contain only properties and methods
/- abstract classes can contain feilds , properties and methods.
/- Both abstract and interfaces can not contain distructors and as well as constructors.
/Doubt how to access these explicit definitions [explicit means:with out public].
Thursday, October 16, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment