In my MVP app, my model (a service) returns a collection of ISession
pointers. Each pointer points to an object of a derived type HttpSession
or HttpsSession
. The model (the service) knows nothing about any GUI, Views, Presenters, etc.
In my Presenter, I need to create and show a View, which should be different depending on the type of the session. How can I do this without using dynamic_cast
check on the pointers and without making ISession
-- and thus the model (the service) -- know about the existence of the GUI, MVP, etc.?
Note: In general, I have the same problem with writing the sessions' data into DB. The Presenter should call the database manager and it should write the sessions into the DB. But I don't understand how it can differentiate between the two types of the sessions without using the check on the dynamic type of the session. I just decided to choose one of the problems and ask here. Help me, please. I read and read about visitor, strategy, etc. patterns, but still cannot grab how developers normally do it.
ISession
to make them distinguishable. Implementing the visitor pattern is one way to do this, but maybe avirtual bool is_secure() const = 0
method would be enough. If this is actually about HTTP vs HTTPS, note that nowadays the only reasonable response to a HTTP request is to respond with a permanent redirect to the HTTPS version (with very few exceptions). Such a redirect would typically be handled in a reverse proxy, before the backend with your business logic is reached.ISession
perhaps you could remove inheritance and any relationships between the classes then use separate functions or services for each Model, returning the correct type directly.