79582143

Date: 2025-04-19 08:02:08
Score: 8
Natty: 7
Report link

So, a question related to this. How do I dynamically create an instance of an object that is 1 of many that implement an interface? For example, in the example above, say there are 3 types of user, but I only want to create an instance of 1 of them at any given moment. I suppose you could put each of them in their own class or method and call the appropriate class/method, but that adds an extra unneeded level of abstraction. Thanks in advance.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): How do I
  • RegEx Blacklisted phrase (3): Thanks in advance
  • No code block (0.5):
  • Contains question mark (0.5):
  • Single line (0.5):
  • Looks like a comment (1):
  • Low reputation (1):
Posted by: matthew