Last active
February 17, 2021 16:18
-
-
Save NMillard/44f90705317cacf27942d06632da912a to your computer and use it in GitHub Desktop.
medium article 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Iban { | |
private readonly string plainIban; | |
private Iban(string iban) { | |
if (!Validate(iban)) throw new ArgumentException(); | |
plainIban = iban; | |
} | |
private bool Validate(string ibanToValidate) { | |
// validation (check length, validate check digits and sum, etc.) | |
return true; | |
} | |
public static implicit operator Iban(string iban) { | |
return new Iban(iban); | |
} | |
} | |
/* | |
* Client code can use it like below | |
*/ | |
Iban account = "DK5000400440116243" // <- validation now runs on the string aswell | |
WithdrawMoney(account, 100); | |
WithdrawMoney("DK5000400440116243", 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment