JAVA_INTERVIEW_LIB Telegram 726
ℹ️ Что такое Dependency Injection?

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;
}
Please open Telegram to view this post
VIEW IN TELEGRAM



tgoop.com/java_interview_lib/726
Create:
Last Update:

ℹ️ Что такое Dependency Injection?

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 | вопросы с собеседований


Share with your friend now:
tgoop.com/java_interview_lib/726

View MORE
Open in Telegram


Telegram News

Date: |

1What is Telegram Channels? Ng Man-ho, a 27-year-old computer technician, was convicted last month of seven counts of incitement charges after he made use of the 100,000-member Chinese-language channel that he runs and manages to post "seditious messages," which had been shut down since August 2020. During a meeting with the president of the Supreme Electoral Court (TSE) on June 6, Telegram's Vice President Ilya Perekopsky announced the initiatives. According to the executive, Brazil is the first country in the world where Telegram is introducing the features, which could be expanded to other countries facing threats to democracy through the dissemination of false content. 4How to customize a Telegram channel? Choose quality over quantity. Remember that one high-quality post is better than five short publications of questionable value.
from us


Telegram Библиотека собеса по Java | вопросы с собеседований
FROM American