123avi (31) [Avatar] Offline
Wouldn't it better that the close method will return Try[CloseAccount] and open will return Try[ActiveAccount] this way
credit and debit and close will be able to accept a:ActiveAccount or something like
def debit[A <:ActiveAccount](a: A, amount: Amount): Try[A]

and it seems more expressive. is that make sense ?
Debasish Ghosh (116) [Avatar] Offline
We can do that. The technique is used to enforce type level restriction to prevent illegal states in entities. There's an entire section devoted to using this technique. Have a look at section 4.5.2 where we use Phantom Types to do implement this for another use case.