Intro to Spring Framework Flashcards
How does a framework differ from a library?
A framework dictates the overall architecture, controls the flow of the application, and imposes certain rules, while a library offers specific functionalities that developers can use as needed within their applications.
What is coherence in a software system?
Coherence refers to the state where all components of a software system work together seamlessly, maintaining consistency and uniformity in their behavior and interactions.
How can consistent coding practices contribute to coherence?
Adopting consistent coding standards, naming conventions, and design patterns across the software system ensures uniformity, readability, and easier collaboration among developers.
How does centralized data management contribute to system coherence?
Centralized data management ensures that all parts of the system access and modify data consistently, avoiding conflicts and discrepancies in information across different components.
What is Dependency Injection (DI)?
Dependency Injection is a design pattern where the dependencies of a component are provided or “injected” from the outside rather than created within the component itself.
What problem does Dependency Injection aim to solve?
Dependency Injection addresses tight coupling between components by removing their direct dependencies on other components or services, making them more reusable and easier to maintain.
What are the key components in Dependency Injection?
In DI, there are typically three main components: the client or consumer that requires a service or dependency, the service or dependency itself, and the injector that provides the dependency to the client.
What are the types of Dependency Injection?
There are primarily three types of DI: Constructor Injection, Setter Injection, and Interface Injection. Constructor Injection and Setter Injection are the most commonly used forms.
What are the benefits of Dependency Injection?
DI promotes code reusability, testability, and easier maintenance by reducing coupling between components, making the application more flexible and easier to extend or modify.
How is dependency achieved between classes through an interface in Java?
In Java, dependency between classes through an interface is established by having a class implement an interface, and another class consuming that interface.
What is an example of an interface in Java that defines a contract?
// Example of an interface defining a contract
public interface MessagingService {
void sendMessage(String message);
}
How can a class implement an interface in Java?
// Example of a class implementing an interface
public class EmailService implements MessagingService {
@Override
public void sendMessage(String message) {
// Implementation specific to sending emails
System.out.println(“Sending email: “ + message);
}
}
How can another class depend on the interface rather than the concrete implementation?
// Example of a class depending on the interface
public class NotificationService {
private MessagingService messagingService;
// Constructor or setter for dependency injection public NotificationService(MessagingService messagingService) { this.messagingService = messagingService; } public void sendNotification(String message) { // Using the interface method, unaware of the concrete implementation messagingService.sendMessage(message); } }
How does this approach aid in flexibility and extensibility?
By depending on the MessagingService interface, NotificationService can be easily switched to use different implementations (e.g., EmailService, SMSService) without modifying its code.
What is the Dependency Inversion Principle (DIP)?
The Dependency Inversion Principle is a design principle that states that high-level modules/classes should not depend on low-level modules/classes. Instead, both should depend on abstractions.