In a large-scale C++ project, two classes, Logger and FileHandler, are tightly coupled, sharing a lot of private data between them using friendship. How might you refactor these classes to reduce coupling without losing functionality? 

  • Combine both classes into a single class. 
  • Extract shared functionality into a separate utility class. 
  • Create global variables for shared data. 
  • Introduce an intermediary interface.
Introducing an intermediary interface or abstraction can decouple these classes. This interface can define the necessary methods and data that both classes need, allowing them to interact without direct access to each other's private data, leading to better separation of concerns.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *