Skip to content

Pattern solutions#3

Open
Goshak95 wants to merge 23 commits intoSArchieEdu:mainfrom
Goshak95:main
Open

Pattern solutions#3
Goshak95 wants to merge 23 commits intoSArchieEdu:mainfrom
Goshak95:main

Conversation

@Goshak95
Copy link

No description provided.

Copy link
Owner

@SArchieEdu SArchieEdu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хорошая работа

export class SuccessControl {
create (type = '') {
// todo: implement logic
if (type === 'button') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

такое проще через switch case делать

price = 1;

// todo: add implementation
// Смущает что получилось два одинаковых решения для Milk и для Sugar
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в этом задании это ок

}
start () {
// todo: add implementation
this.hero.name = 'Barbarian';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше через конструктов, тк там есть аткая возможность

init () {
this.addGetSize();

// Непонятно какая дополнительная логика должна быть добавлена
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (const child of this.compositeItem.children) {
      child.accept(Visitor);
    }


addGetSize () {
// todo: add implementation
this.compositeItem.getSize = () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addGetSize () {
    let count = 0;

    this.compositeItem.getSize = () => {
      count += 1;

      for (const child of this.compositeItem.children) {
        count += child.getSize();
      }

      return count;
    };
  }

@@ -1,9 +1,21 @@
// Непонятно для чего здесь класс Memento, раз нам не важно реализация состояния класса Hero,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export class Memento {
  #state = {};

  constructor (state = {}) {
    this.#state = JSON.parse(state);
  }

  getState () {
    return this.#state;
  }
}

export class History {
  #snapshots = [];

  add (snapshot = {}) {
    this.#snapshots.unshift(snapshot);

    return this.#snapshots.at(0);
  }
}

export class Hero {
  #name = '';

  #state = {
    level: 1,
    skills: [],
  };

  constructor(name = '', history = {}) {
    this.#name = name;
    this.history = history;
  }

  get state () {
    return this.#state;
  }

  addSkill (skill) {
    this.#state.skills.push(skill);
  }

  increaseLevel () {
    this.#state.level += 1;
  }

  load (snapshot = {}) {
    this.#state = snapshot.getState();
  }

  save () {
    return this.history.add(new Memento(JSON.stringify(this.#state)));
  }
}

// todo: implement
if (this.regExp.test(data)) {
/*
Непонятно для чего нужно свойство next, если можно записать короче:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для единообразия работы с элементами цепочки


export class ProxyUser {
// Не понимаю зачем здесь это свойство
rights = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это моя опечатка

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants