classes.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {Author, Book, DamageLogger, Librarian} from './interfaces';
  2. class UniversityLibrarian implements Librarian {
  3. department: string;
  4. email: string;
  5. name: string;
  6. assistCustomer(custName: string): void {
  7. console.log(`${this.name} is assisting ${custName}.`);
  8. }
  9. }
  10. class ReferenceItem {
  11. static department = 'Research';
  12. private _publisher: string;
  13. constructor(public title: string, protected year: number) {
  14. }
  15. printItem(): void {
  16. console.log(`${this.title} was published in ${this.year}`);
  17. console.log(`Department: ${ReferenceItem.department}.`);
  18. }
  19. get publisher(): string {
  20. return this._publisher.toUpperCase();
  21. }
  22. set publisher(p: string) {
  23. this._publisher = p;
  24. }
  25. }
  26. class Encyclopedia extends ReferenceItem {
  27. constructor(newTitle: string, newYear: number, public edition: number) {
  28. super(newTitle, newYear);
  29. }
  30. printItem(): void {
  31. super.printItem();
  32. console.log(`Edition: ${this.edition} (${this.year}).`);
  33. }
  34. }
  35. class Journal extends ReferenceItem {
  36. public contributors: string[];
  37. constructor(title: string, year: number) {
  38. super(title, year);
  39. }
  40. }
  41. export { Encyclopedia, ReferenceItem, UniversityLibrarian };