I recently worked on a file explorer within a console window (like Midnight Commander). I want to use ncurses as library. I have encountered some fundamental problems with my design and searched on the Internet for solutions and better practices.
However I ended up scrutinising my whole programming work and my approach to problems. I have always stuck to Singletons and started to develop a pattern, that uses different Managers to complete different tasks, that should be separated (e.g. Database, GUI, Networking). I read on the Internet and heard from colleagues, that Singletons are bad and that I should stop using them. I was able to use static references to access the managers.
So the basic structure of my problem is like this:
DirectoryController
One instance (or tab) that contains files and a path
It is like the logical representation of a file view
DirectoryManager
Manages all the directory controllers
GUIManager
Manages the GUI and needs somehow access to the current directory controller
(Most likely over the DirectoryManager)
KeyboardManager
Gets input of the user
Uses the dir controller to update path and move current selected files
I want to separate these functionalities, because I think it is better to separate different tasks into task groups.
Maybe I am doing something wrong but I just can't think of a different solution, how to split up these functionalities and still be able to use functionalities of another group :/
Edit:
I have the same problem with libraries like FLASK for python. How am I supposed to store and access shared data when all of the FLASK functions and all of the REST endpoints are static functions? I think that I somehow have to have a object, that is accessible by all of these functions.
But I cannot think of a solution for this either.