Created
June 20, 2011 15:21
-
-
Save karanmalhi/1035813 to your computer and use it in GitHub Desktop.
Example of an advanced enum
This file contains hidden or 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
package com.lq; | |
public enum CreditCardType { | |
VISA("111-22-3333") { | |
@Override | |
public boolean isValid() { | |
System.out.println("Validating a " + this.name()); | |
return false; | |
} | |
}, | |
MASTERCARD("0123456789") { | |
@Override | |
public boolean isValid() { | |
System.out.println("Validating a " + this.name()); | |
return false; | |
} | |
}, | |
AMEX("37957893457834") { | |
@Override | |
public boolean isValid() { | |
System.out.println("Validating a " + this.name()); | |
return false; | |
} | |
}; | |
private String number; | |
private CreditCardType(String number) { | |
this.number = number; | |
} | |
public abstract boolean isValid(); // write card specific validation | |
// LUND's formula | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment