123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import * as I from './interfaces';
- import {CatalogItem, Inventory} from "./interfaces";
- class UniversityLibrarian implements I.Librarian {
- department: string;
- email: string;
- name: string;
- assistCustomer(custName: string): void {
- console.log(`${this.name} is assisting ${custName}.`);
- }
- }
- abstract class ReferenceItem {
- static department = 'Research';
- private _publisher: string;
- constructor(public title: string, protected year?: number) {
- }
- printItem(): void {
- console.log(`${this.title} was published in ${this.year}`);
- console.log(`Department: ${ReferenceItem.department}.`);
- }
- get publisher(): string {
- return this._publisher.toUpperCase();
- }
- set publisher(p: string) {
- this._publisher = p;
- }
- abstract printCitation(): void;
- }
- class Journal extends ReferenceItem {
- public contributors: string[];
- constructor(title: string, year: number) {
- super(title, year);
- }
- printCitation(): void {
- console.log(`${this.title} - ${JSON.stringify(this.contributors)}.`);
- }
- }
- class Catalog<T extends CatalogItem> implements Inventory<T> {
- private catalogItems = new Array<T>();
- addItem(newItem: T): void {
- this.catalogItems.push(newItem);
- }
- getAllItems(): Array<T> {
- return this.catalogItems;
- }
- getNewestItem(): T {
- return this.catalogItems.slice(-1)[0];
- }
- }
- export { Catalog, Journal, ReferenceItem, UniversityLibrarian };
|