VatNumber, BankingAccount Question RRS feed

  • Question

  • Since the VAT numbers in different European countries have different algorithms should I create separate classes based on an abstract class or interface OR should I create just different static validation (public static bool IsValidVatNumber(strinf VatNumber) methods in a helper/utility class?

    The same question for BankingAccountNumbers?



    Friday, July 22, 2011 9:21 PM

All replies

  • I think I'd have one method taking string VatNumber and string country.

    Just a switch returning the regex to apply.

    Way clearer than 80 something classes and inheritance, IMO.

    Saturday, July 23, 2011 8:20 PM
  • @Andy thanks.
    What about instead of having one method IsValidVatNumber(string country, string vatNumber) in eg class Utility having a VatNumber class with properties CountryCode and Number and having the method IsValidNumber in there using a switch based on the CountryCode?



    Sunday, July 24, 2011 8:10 AM
  • Yes, sounds good.



    You could have an enumeration of countries with custom attributes defining the regex for vat and bank A/c.

    I kind of like that approach because you've got the one list of stuff (countries) and it's attributes.


    The thing that would make a difference to me is if there's some logic other than just a regex involved.

    So if you needed several if statements and whatnot then I'd define an interface and have a factory return a concrete object.

    As it is, I don't think you need more than the regex to change by country so you can use a simpler approach.


    If there were other differences for countries.

    If you need a class per country for some other reason then you may as well stick with that rather than have two mechanisms.

    Sunday, July 24, 2011 10:12 AM
  • Hi

    You can also think of having dictionary map of country code to delegate. when you ask for validate gets the delegate from map and validate the VATNumber..

    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    Monday, July 25, 2011 4:59 PM