나는 다음과 같은 클래스가 :콜링 기본 클래스 생성자
public abstract class BusinessRule
{
public string PropertyName { get; set; }
public string ErrorMessage { get; set; }
public BusinessRule(string propertyName)
{
PropertyName = propertyName;
ErrorMessage = propertyName + " is not valid";
}
public BusinessRule(string propertyName, string errorMessage)
: this(propertyName)
{
ErrorMessage = errorMessage;
}
}
그리고
public class ValidateId : BusinessRule
{
public ValidateId(string propertyName) : base(propertyName)
{
ErrorMessage = propertyName + " is an invalid identifier";
}
public ValidateId(string propertyName, string errorMessage)
: base(propertyName)
{
ErrorMessage = errorMessage;
}
public override bool Validate(BusinessObject businessObject)
{
try
{
int id = int.Parse(GetPropertyValue(businessObject).ToString());
return id >= 0;
}
catch
{
return false;
}
}
}
그리고 고객 클래스 내에서
public class Customer : BusinessObject
{
public Customer()
{
AddRule(new ValidateId("CustomerId"));
}
}
나는 새로운 비즈니스 규칙을 추가하고를 ValidateId의 생성자가 기본 클래스 생성자를 호출하면 생성자를 호출하여 ValidateId를 호출합니다. 내가 조금 혼란스러워지기 시작한 곳이다.
ValidateId 생성자가 달성하려는 작업을 수행 할 수있는 경우 왜 기본 클래스 생성자를 호출해야합니까?
이 기본 생성자에 있습니다 :
PropertyName = propertyName;
ErrorMessage = propertyName + " is not valid";
이이 ValidateId 생성자에 :의
ErrorMessage = propertyName + " is an invalid identifier";
하나 ValidateId 생성자와 기본 생성자 모두 뭔가에 오류 메시지를 설정하는 것입니다 ErrorMessage는 사용자에게 오류를 표시하는 데 사용됩니까?
또한 나는 : base(propertyName)
를 제거하지 분명히 난 그냥 Businessrule에 매개 변수가없는 생성자를 추가하고 ValidateId 생성자에서 모든 것을 구현할 수있다, 나는 BusinessRule이 매개 변수가없는 생성자 오류 메시지가 포함되어 있지 않습니다 얻을 기본 생성자를 호출하지만 무엇을 알고 싶다면 기본 생성자를 호출하거나 호출하지 않는다는 장점/의미는 무엇입니까?
감사
설명해 주셔서 감사합니다. – 03Usr