public abstract class Shape
{
private string _Me = string.Empty;
public string Me
{
get { return _Me; }
}
public void CallMe()
{
Console.WriteLine("i am calling from Base");
}
public void ColorShapes(Shape Shape)
{
if (Shape is Circle)
{
// calling circle dal
}
else if (Shape is Triangle)
{
}
}
}
public class Circle : Shape
{
public string CircleID { get; set; }
public string CircleLogo { get; set; }
public string CircleColor { get; set; }
public void CircleMe() { }
}
public class Triangle : Shape
{
public string TriangleID { get; set; }
public string TriangleLogo { get; set; }
public string TriColor { get; set; }
public void TriMe() { }
}
//Shape _s = new Circle();
//((Circle)_s).CircleColor = "Red";
//((Circle)_s).CircleID = "1";
//((Circle)_s).CircleLogo = "Flag";
//_s.ColorShapes(_s);
//((Circle)_s).CircleMe();
or this one
Circle _c = new Circle();
_c.ColorShapes(_c);
tan_vision_1...
Participant
1178 Points
413 Posts
Polymorphism-which is faster and better
Apr 30, 2012 12:26 PM|LINK
public abstract class Shape { private string _Me = string.Empty; public string Me { get { return _Me; } } public void CallMe() { Console.WriteLine("i am calling from Base"); } public void ColorShapes(Shape Shape) { if (Shape is Circle) { // calling circle dal } else if (Shape is Triangle) { } } } public class Circle : Shape { public string CircleID { get; set; } public string CircleLogo { get; set; } public string CircleColor { get; set; } public void CircleMe() { } } public class Triangle : Shape { public string TriangleID { get; set; } public string TriangleLogo { get; set; } public string TriColor { get; set; } public void TriMe() { } }//Shape _s = new Circle(); //((Circle)_s).CircleColor = "Red"; //((Circle)_s).CircleID = "1"; //((Circle)_s).CircleLogo = "Flag"; //_s.ColorShapes(_s); //((Circle)_s).CircleMe(); or this one Circle _c = new Circle(); _c.ColorShapes(_c);