You can encapsulate payment in his own ValueObject :
exportclassAccount{privateAccountPaymentMethodpaymentMethod;addPaymentMethod(paymentMethod:IPaymentMethod):void{this.paymentMethod=this.paymentMethod.addMethod(paymentMethod);}}classAccountPaymentMethod{constructor(private_paymentMethods:IPaymentMethod[],private_defaultPaymentMethod:IPaymentMethod){}default():IPaymentMethod{returnthis._defaultPaymentMethod;}changeDefault(paymentMethod:IPaymentMethod):AccountPaymentMethod{returnnewAccountPaymentMethod(this._paymentMethods,paymentMethod);}removeMethod(paymentMethod:IPaymentMethod):AccountPaymentMethod{thrownewError("Method not implemented.");}addMethod(paymentMethod:IPaymentMethod):AccountPaymentMethod{paymentMethod.init(this);returnnewAccountPaymentMethod([...this._paymentMethods,paymentMethod],_defaultPaymentMethod:IPaymentMethod);}}
And I thinks your method create is too generic, you can be more explicit :
typePaymentMethodParam={paymentMethods:IPaymentMethod[]defaultPaymentMethod:IPaymentMethod}exportclassAccount{staticcreate(user:User,{paymentMethods,defaultPaymentMethod}:PaymentMethodParam):Result<Account>{// ...}staticcreateAccountForFutur(user:User,createdAt:Date/* Date encapsulate Moment for the day Moment will be abandonned */):Result<Account>{// for some reason, you wants to create an Account with createdAt !== today// and you don't want to let them pay}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You can encapsulate payment in his own ValueObject :
It looks really interesting and I like your approach to encapsulate logic with payment methods in one object. Thanks!
And I thinks your method create is too generic, you can be more explicit :