Created
January 31, 2023 17:32
-
-
Save HenriqueSilverio/85834082104aaa5e5316c08506e7cf68 to your computer and use it in GitHub Desktop.
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
abstract class Entity<T> { | |
public readonly id: T | |
protected abstract nextID(): T | |
constructor(id?: T) { | |
this.id = id || this.nextID() | |
} | |
} | |
class EntityWithUUID extends Entity<UUID> { | |
protected nextID(): UUID { | |
return new UUID() | |
} | |
} | |
class EntityWithObjectID extends Entity<ObjectID> { | |
protected nextID(): ObjectID { | |
return new ObjectID() | |
} | |
} | |
class UUID { | |
public readonly value: string = 'Mock UUID' | |
} | |
class ObjectID { | |
public readonly value: string = 'Mock ObjectID' | |
} | |
class Author extends EntityWithUUID {} | |
class Book extends EntityWithObjectID {} | |
const a = new Author() | |
const b = new Book() | |
console.log(a.id.value) | |
console.log(b.id.value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment