In the OfflinePruner struct, the fields inputDB and filterDatabase are of type database.Database. The database.Database interface contains many methods, but OfflinePruner does not need all of them. Specifically, filterDatabase only needs Get() and Put(), while inputDB only needs Close().
Interface Segregation Principle:Ensures that clients only depend on the methods they use, promoting a cleaner and more modular design.
Principle of Least Privilege: Reduces access to only necessary methods, minimizing potential for misuse and improving security. Principle of Least Privilege.
Reduced External Dependency: Avoids coupling OfflinePruner to the entire database.Database interface, making it resilient to future changes in the database.Database interface.
Ensuring Focused Functionality: Prevents types or classes from being burdened with unnecessary functionality.
Reduces Complexity: Smaller, focused interfaces are easier to understand and maintain.
Enhances Security:Limiting access to only required methods reduces the risk of accidental misuse.
Improves Robustness: Fewer methods mean fewer opportunities for bugs or errors.
Facilitates Testing: Smaller interfaces are easier to mock and test because there are fewer methods to simulate.
Issue summary
In the OfflinePruner struct, the fields inputDB and filterDatabase are of type database.Database. The database.Database interface contains many methods, but OfflinePruner does not need all of them. Specifically, filterDatabase only needs Get() and Put(), while inputDB only needs Close().
It is better to define two local interfaces that contain only the methods needed. The benefits of this approach include:
Related Issues:
3975