I’m building a class that interacts with an API. Say the API has a “get_something” method for “foo” objects and “bar” objects. I want my class to expose a “get_something” method, but be able to distinguish if it’s for “foo” or for “bar.”
What’s a good solution for me? Can I create a class that has multiple name spaces? Would that be a good idea?
Maybe I should have nested classes?
you should look at namespaces as packages in java. a class belongs to 1 package only
what you can do though is have
in that case class A will exist under namespace A_NS, and another class A’ will exist under B_NS, which will extend class \NS_A\A;
you could check an object’s class, or implement some identifier inside to distinguish.
overall, i would recommend that the design of your system will treat each class as if it belongs to 1 namespace only.