classes.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import * as I from './interfaces';
  2. import {CatalogItem, Inventory} from "./interfaces";
  3. class UniversityLibrarian implements I.Librarian {
  4. department: string;
  5. email: string;
  6. name: string;
  7. assistCustomer(custName: string): void {
  8. console.log(`${this.name} is assisting ${custName}.`);
  9. }
  10. }
  11. export abstract class ReferenceItem {
  12. static department = 'Research';
  13. private _publisher: string;
  14. constructor(public title: string, protected year?: number) {
  15. }
  16. printItem(): void {
  17. console.log(`${this.title} was published in ${this.year}`);
  18. console.log(`Department: ${ReferenceItem.department}.`);
  19. }
  20. get publisher(): string {
  21. return this._publisher.toUpperCase();
  22. }
  23. set publisher(p: string) {
  24. this._publisher = p;
  25. }
  26. abstract printCitation(): void;
  27. }
  28. class Journal extends ReferenceItem {
  29. public contributors: string[];
  30. constructor(title: string, year: number) {
  31. super(title, year);
  32. }
  33. printCitation(): void {
  34. console.log(`${this.title} - ${JSON.stringify(this.contributors)}.`);
  35. }
  36. }
  37. class Catalog<T extends CatalogItem> implements Inventory<T> {
  38. private catalogItems = new Array<T>();
  39. addItem(newItem: T): void {
  40. this.catalogItems.push(newItem);
  41. }
  42. getAllItems(): Array<T> {
  43. return this.catalogItems;
  44. }
  45. getNewestItem(): T {
  46. return this.catalogItems.slice(-1)[0];
  47. }
  48. }
  49. export { Catalog, Journal, UniversityLibrarian };