In the Enterprise Library, how does the abstract Validator.cs have a method definition?
Consider this piece of code:
public abstract class Validator
{
protected Validator()
{
}
pro开发者_运维知识库tected abstract void ValidateCore(object instance, string value, IList<ValidationResult> results);
public void Validate(object instance, string value, IList<ValidationResult> results)
{
if (null == instance) throw new ArgumentNullException("instance");
if (null == results) throw new ArgumentNullException("results");
ValidateCore(instance, value, results);
}
}
Look at the Validate()
overload, how can an abstract class have definitions like this?
An abstract class should have at least one abstract method. It does not mean it can't define concrete methods. One of the usages of this property is the Template Method design pattern which lets you define an algorithm in a way that it can be changed by subclasses.
I think it is perfectly normal. That's called Template Method pattern. Right?
http://en.wikipedia.org/wiki/Template_method_pattern
精彩评论