Skip to content

Instantly share code, notes, and snippets.

@circus2271
Last active May 19, 2024 18:47
Show Gist options
  • Save circus2271/d664a1d953978070e95ef0c99626c80e to your computer and use it in GitHub Desktop.
Save circus2271/d664a1d953978070e95ef0c99626c80e to your computer and use it in GitHub Desktop.
// const log = (name: string) => {
// console.log(name)
// }
// log('blabla')
class Logger {
log(name: string) {
console.log(name)
}
}
const logger = new Logger()
logger.log('jack')
class Dog {
logger = new Logger()
bark() {
this.logger.log('bark')
// this.logger.dog('bark')
}
}
const dog = new Dog()
dog.bark()
// console.log(logger.dark)
interface Reader {
read: () => void;
}
class Human implements Reader {
bookShelf?: BookShelf;
constructor(bookShelf: BookShelf) {
this.bookShelf = bookShelf
}
read() {
console.log('hmmm')
}
hasBooks(): boolean {
if (this.bookShelf) {
return this.bookShelf.books.length > 0
}
return false
}
}
class BookShelf {
constructor(private _books: Book[]) {}
get books(): Book[] {
return this._books
}
}
interface Book {
name: string;
// title: string;
author?: string;
publisher?: string;
}
const jacksBooks: Book[] = [
{
name: 'Bhagavad Gita'
}
]
const jacksBookShelf = new BookShelf(jacksBooks)
const jack = new Human(jacksBookShelf)
console.log('jack has books: ', jack.hasBooks())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment