classes.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import * as I from './interfaces';
  2. class UniversityLibrarian implements I.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. abstract 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. abstract printCitation(): void;
  26. }
  27. class Encyclopedia extends ReferenceItem {
  28. constructor(newTitle: string, newYear: number, public edition: number) {
  29. super(newTitle, newYear);
  30. }
  31. printItem(): void {
  32. super.printItem();
  33. console.log(`Edition: ${this.edition} (${this.year}).`);
  34. }
  35. printCitation(): void {
  36. console.log(`${this.title} - ${this.year}.`);
  37. }
  38. }
  39. class Journal extends ReferenceItem {
  40. public contributors: string[];
  41. constructor(title: string, year: number) {
  42. super(title, year);
  43. }
  44. printCitation(): void {
  45. console.log(`${this.title} - ${JSON.stringify(this.contributors)}.`);
  46. }
  47. }
  48. export { Encyclopedia, Journal, ReferenceItem, UniversityLibrarian };