Programming pattern / architectural question

前端 未结 6 1410
生来不讨喜
生来不讨喜 2021-02-10 13:50

I am currently working on a project where I have a BankAccount entity for some other entity.

Each bank account as a reference to a bank entity, an account number and opt

6条回答
  •  借酒劲吻你
    2021-02-10 14:28

    I'd make it aspect oriented and reduce coupling.

        [IBANVlidator(Message = "your error message. can also come from culture based resouce file.")]
        public string IBAN
        {
            get
            {
                return _iban;
            }
            set
            {
                this.validate();
                _iban = value;
            }
        }
    

    this.validate() is called from the base class of your BankAccount which iterates through all properties having validation attribute. validation atributes are custom attributes derived from ValidationAttribute class which can target class properties.

    IBAN validation responsibility then is given to IBANValidator validation-attribute. of course this design can be improved which is beyond the scope of this answer.

提交回复
热议问题