So, I have four classes:
App is the entry point for the application.
MainPage is the main screen
Authenticator is an authentication helper / utility class
LoginPage is a login screen.
App, MainPage and LoginPage have pointers to Authenticator and are actually transferred from the application to MainPage, to LoginPage, when the user launches the application, reaches the main screen and the log is requested. The application creates MainPage, and if MainPage needs to log in, it creates LoginPage. The Authenticator pointer is passed at creation.
Let's say Authenticator looks something like this:
class Authenticator { public: std::string GetToken() const; void Login(std::string username, std::string pass); }
Now the application will create a regular, non-constant pointer to the Authenticator, but since I do not want MainPage to modify the Authenticator, I want it to save the const pointer for it (i.e. it can only call const functions of the member on it). However, I would like LoginPage to call non-constant member functions like Login (), so when I pass my Authenticator from MainPage to LoginPage, I need to drop the constant.
My question is : is this bad in this situation? Should a class that does not have the right to modify an object pass it to one that can? Or would it be better if the application simultaneously created MainPage and LoginPage and gave them the same Authenticator to get started? My only problem with this option is that I am creating LoginPage actively, not lazily, and I would rather do it lazily.
Thanks in advance.
source share