Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Task } from '../models/task.model';
- export class Board {
- private _tasks: Task[];
- private static _referenceCount: number = 0;
- constructor() {
- this._tasks = [];
- Board._referenceCount++ ;
- }
- public get referenceCount(): number {
- return Board._referenceCount;
- }
- public get tasks(): Task[] {
- return this._tasks;
- }
- public get taskCount(): number {
- return this._tasks.length;
- }
- public add(task: Task): void {
- if (this._tasks.includes(task)) {
- throw new Error('You already have this task!');
- }
- this._tasks.push(task);
- }
- public remove(task: Task): void {
- const index = this._tasks.indexOf(task);
- if (index > -1) {
- this._tasks.splice(index, 1);
- } else {
- throw new Error('There is no task in the list!');
- }
- }
- toString() {
- if (this._tasks.length === 0) {
- return `
- ---Task Board---
- Tasks:
- No tasks at the moment.`;
- } else {
- return `
- ---Task Board---
- Tasks:
- ${this._tasks.join(`--------`)}
- `}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement