Inheritance

Given two classes in which one inherits from the other:

public class Widget
{  
  public string Color { get; set };
}

public class ExtendedWidget : Widget
{
  public string Size { get; set; };
}

And you've created two specifications:
public class WidgetSpec : Validates<Widget>
{  
  public WidgetSpec()
  {
    Check(w => w.Color).Required().And.MaxLength(20);
  }
}

public class ExtendedWidgetSpec : Validates<ExtendedWidget>
{
  public ExtendedWidgetSpec()
  {
    Check(w => w.Color).Required().And.MaxLength(20);
    Check(w => w.Size).Required().And.MaxLength(10);
  }
}

You'll notice that the Check for Color is repeated in the ExtendedWidgetSpec. In order to use check the WidgetSpec as part of ExtendedWidgetSpec, add:

Using<Widget, WidgetSpec>();

The final specification looks like:
public class ExtendedWidgetSpec : Validates<ExtendedWidget>
{
  public ExtendedWidgetSpec()
  {
    Using<Widget, WidgetSpec>();
    Check(w => w.Size).Required().And.MaxLength(10);
  }
}



Last edited Feb 2, 2010 at 10:26 PM by TechnoAg, version 1

Comments

No comments yet.