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.
Loading...
Related Quiz
- Which of the following C++ versions introduced the auto keyword for automatic type deduction?
- Imagine a function that performs file I/O and may throw an exception. What might be a concern if this function is used inside a constructor, and how might it be addressed?
- How might you address concerns about function templates impacting compilation times and binary size in a high-performance scientific computing application?
- A function without any parameters is declared with the keyword _______ in the parentheses.
- Which of the following operators has the highest precedence in C++?