I am trying to understand the cleanest way to design a credentials base class and subclasses.
Say I have base class Credentials. I have multiple different credential types, for example username/password, or certificate etc. So it would make sense to have a child class of Credentials called 'Password' and another called 'Certificate'.
Question 1 - if I make Credentials have a get() method, how do I make it return only the type of credentials I have stored in there? For example if PasswordCred is of type 'Password' and I call the parent get() method, how does the parent know (or should it ever actually know) what to return based on the sub class?
The child class Password could have two members, 'username' and 'password. The child class 'Certificate' could have three members 'certificate', 'private key', 'certificate chain'.
Lets say I have another class called AuthenticateBase, with a method Login which requires Credentials.
Question 2 - If I derive a class from this called CertificateAuthentication, and override the Login method, how would I define or code this in a way that ensures that I'm passing a Certificate and not a Password?
I assume this is a common polymorphic pattern but I just cant wrap my head around the right way to go about it!