123avi (29) [Avatar] Offline
#1
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 (111) [Avatar] Offline
#2
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.

Thanks.