Last active
May 19, 2024 18:47
-
-
Save circus2271/d664a1d953978070e95ef0c99626c80e 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
// 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