Skip to content

Conversation

@TheXlebushek
Copy link

Я не очень понял Вашу реализацию electricity, так что вся структура была изменена.
Вкратце об изменениях:

  • Объект берет на себя всю логику соединения и обработки сигналов (упрощаем жизнь пользователю)
  • Pole умеют оправлять и получать команды, обрабатывая их с помощью заданных объектами callback'ов
  • Максимальная простота создания новых подтипов объектов, достигнутая благодаря полноте родителя
  • Читабельность кода и простота использования интерфейса

Пример кода:

#include "electricity.h"

int main()
{
    Generator g("Generator");
    Switch s("Switch");
    Light l("Light");
    if (g.connect(s) && g.connect(l))
        s.toggle();
}

Вывод:

Lights "Light" are now on

А еще бонус: пикча с котиком
image

@TheXlebushek TheXlebushek changed the title Тут сразу вся домашка КМБО-03-21 Чертков Глеб May 24, 2022


protected:
Mammal();
Copy link
Owner

Choose a reason for hiding this comment

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

Не сделано: конструкторы, сразу инициализирующие поля.

/// </summary>
class Object {
std::string name;
static Pole* getNewInstance();
Copy link
Owner

Choose a reason for hiding this comment

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

Почему не подошёл просто конструктор?

{
// TODO
return false;
if (_connectedId == pole.getId())
Copy link
Owner

Choose a reason for hiding this comment

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

Нет сигнализации об ошибке привязки.

return _connectedId;
}

bool Pole::send(const std::string& command)
Copy link
Owner

Choose a reason for hiding this comment

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

o_O

}

const Pole* Switch::getPole(size_t idx) const
Pole* Object::getPoleConnectedTo(const Object& object) const
Copy link
Owner

Choose a reason for hiding this comment

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

Несколько полюсов одного объекта могут быть соединены с несколькими полюсами другого. Простейший пример: батарейка [+] - лампочка - [-] батарейка. Смысл существования данной функции в этом случае не ясен.

{
os << "a_s: " << a_s << " b_s: " << getBString() << " data[] = {";
for (int i = 0; i < 7; ++i) {
os << ((float*) ((std::string*) (this + 1) + 1))[i];
Copy link
Owner

Choose a reason for hiding this comment

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

Почему ((this + 1) + 1)?

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.

2 participants