classes.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 Journal extends ReferenceItem {
  28. public contributors: string[];
  29. constructor(title: string, year: number) {
  30. super(title, year);
  31. }
  32. printCitation(): void {
  33. console.log(`${this.title} - ${JSON.stringify(this.contributors)}.`);
  34. }
  35. }
  36. export { Journal, ReferenceItem, UniversityLibrarian };