Skip to content

Comments

Assignment 6#6

Open
nitintayal008 wants to merge 3 commits intomainfrom
Assignment-6
Open

Assignment 6#6
nitintayal008 wants to merge 3 commits intomainfrom
Assignment-6

Conversation

@nitintayal008
Copy link
Owner

@nitintayal008 nitintayal008 commented May 22, 2024

why this code violating DIP?

public class EmployeeService {
private Database database = new Database();

public void saveEmployee(Employee employee) {
    database.save(employee);
}

}

public class Database {
public void save(Employee employee) {
// Code to save employee to the database
}
}

public class Employee {
private String name;
private String address;

public Employee(String name, String address) {
    this.name = name;
    this.address = address;
}

// Getters and setters

}

Note: This code is violating DIP because "EmployeeService" class is directly dependent on a concrete implementation of the Database class.
This approach violates the Dependency Inversion Principle (DIP) because any change in the database implementation would require modifications to the EmployeeService class. According to DIP, high-level modules such as EmployeeService should depend on abstractions (interfaces) rather than on concrete implementations.

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.

3 participants