DEV Community

Discussion on: How to keep list of different payment methods in a web account following DDD principles?

Collapse
 
benjioe profile image
Benjioe • Edited

And I thinks your method create is too generic, you can be more explicit :


type PaymentMethodParam = {
  paymentMethods: IPaymentMethod[]
  defaultPaymentMethod: IPaymentMethod
}

export class Account {
  static create(user: User, {paymentMethods, defaultPaymentMethod} : PaymentMethodParam): Result<Account> {
     // ...
  }
  static createAccountForFutur(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
  }
}
Enter fullscreen mode Exit fullscreen mode