Dependency Injection (внедрение зависимостей) — это один из основных паттернов проектирования в программировании, который позволяет объектам получать свои зависимости извне, вместо того чтобы создавать их внутри себя.
DI способствует:
— Слабой связанности между компонентами. — Легкости тестирования за счет использования mock-объектов. — Повторному использованию кода.
Основные способы внедрения зависимостей:
🔹 Constructor Injection Зависимости передаются через конструктор.
public class Service { private final Repository repository;
public Service(Repository repository) { this.repository = repository; } }
🔹Setter Injection Зависимости передаются через сеттеры.
public class Service { private Repository repository;
public void setRepository(Repository repository) { this.repository = repository; } }
🔹 Field Injection Зависимости внедряются напрямую в поля класса (обычно с помощью фреймворков, например Spring).
@Component public class Service { @Autowired private Repository repository; }
Dependency Injection (внедрение зависимостей) — это один из основных паттернов проектирования в программировании, который позволяет объектам получать свои зависимости извне, вместо того чтобы создавать их внутри себя.
DI способствует:
— Слабой связанности между компонентами. — Легкости тестирования за счет использования mock-объектов. — Повторному использованию кода.
Основные способы внедрения зависимостей:
🔹 Constructor Injection Зависимости передаются через конструктор.
public class Service { private final Repository repository;
public Service(Repository repository) { this.repository = repository; } }
🔹Setter Injection Зависимости передаются через сеттеры.
public class Service { private Repository repository;
public void setRepository(Repository repository) { this.repository = repository; } }
🔹 Field Injection Зависимости внедряются напрямую в поля класса (обычно с помощью фреймворков, например Spring).
@Component public class Service { @Autowired private Repository repository; }
BY Библиотека собеса по Java | вопросы с собеседований
The court said the defendant had also incited people to commit public nuisance, with messages calling on them to take part in rallies and demonstrations including at Hong Kong International Airport, to block roads and to paralyse the public transportation system. Various forms of protest promoted on the messaging platform included general strikes, lunchtime protests and silent sit-ins. The public channel had more than 109,000 subscribers, Judge Hui said. Ng had the power to remove or amend the messages in the channel, but he “allowed them to exist.” Telegram Channels requirements & features The optimal dimension of the avatar on Telegram is 512px by 512px, and it’s recommended to use PNG format to deliver an unpixelated avatar. But a Telegram statement also said: "Any requests related to political censorship or limiting human rights such as the rights to free speech or assembly are not and will not be considered."
from us