A
A
Aricus2021-04-14 11:13:23
PHP
Aricus, 2021-04-14 11:13:23

How to make the dependency more abstract?

There is such a dependence (in a simplified form):

// Класс ошибок
class Err {
  // Запись сообщения
  public function remember($mess) {
    ...
  }
}
// Класс файлов
class File {
  // Вывести ошибку
  protected function setError(string $error) {
    $this->ok = false;
    (new Err)->remember('Ошибка в папке '.$this->cut('').':<br>'.$error);
  }
}

I understand that this dependency needs to be abstracted so that the File class (and other classes made within the project) can be transferred without changes to another project where errors are written differently. How exactly can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vitaly_74, 2021-04-14
@Aricus

Try using interfaces. But from project to project. you can’t guess with methods, so from project to project you will have to use the adapter + interface pattern. adapter to guess with method name, in new project. but it's all rubbish. but i answered your question

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question