Skip to content

Instantly share code, notes, and snippets.

@HenriqueSilverio
Created January 31, 2023 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HenriqueSilverio/85834082104aaa5e5316c08506e7cf68 to your computer and use it in GitHub Desktop.
Save HenriqueSilverio/85834082104aaa5e5316c08506e7cf68 to your computer and use it in GitHub Desktop.
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