The idea of a class
AuthHost implemented in terms of an interface
Auth is that the class stays generic, with no compile time knowledge which of the available
Auth implementations will be actually used at run time.
But when such a class contains methods like
onTwitterClick, this contradicts the genericity. So if
AuthHost is not supposed to be generic, then one can add simply two member variables of type
TwitterAuth, initialize and use them accordingly.
However, I guess you want to know how to design
AuthHost generic manner. Assumed
AuthHost is some user interface class, the UI elements for the different authentification services need to be initialized or generated at run time (for example, a dynamically generated button for each available authentication service, or a dynamically filled list element from which the user has to choose one row. For making this possible, the interface
Auth will have to be extended to provide additional meta information.
For example, there should be a function
getName() to provide a name string of the
AuthHost then could contain internally a list (or some other container) of
Auth objects, use
getName() those to fill the visual list for the UI with the names, let the user pick one of the entries and then call
doAuth for the related
Auth object. This will lead to a design where there is no
onTwitterClick method in
AuthHost any more, but only something like an