Skip to content

Instantly share code, notes, and snippets.

@talesmgodois
Last active October 16, 2020 02:06
Show Gist options
  • Save talesmgodois/62937f13b1a296208a7c64a773997283 to your computer and use it in GitHub Desktop.
Save talesmgodois/62937f13b1a296208a7c64a773997283 to your computer and use it in GitHub Desktop.
class EBreeds {
private static map = new Map<string, EBreeds>();
public static readonly AKITA = EBreeds.build('AKITA', 'Cão grande branco e peludo');
public static readonly SCOTTISH_TERRIER = EBreeds.build('SCOTTISH_TERRIER', 'Cão pequeno');
private constructor(
public readonly code: string,
public readonly desc: string
) {}
public toString(): string {
return this.code;
}
public static getEnumByCode(code: string) {
return this.map.get(code);
}
public equals(breed: EBreeds): boolean {
return this.code === breed.code;
}
public equalsCode(code: string): boolean {
return this.code === code;
}
public static build(code: string, desc: string): EBreeds {
const breed = new EBreeds(code, desc);
this.map.set(breed.code, breed);
return breed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment