Jump to content
  • Advertisement
Sign in to follow this  
Wutalife37

Dynamic Class Loading

This topic is 4804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone. I'm working on a game but have run into a bit of a problem. I can't figure out how to access a class with just the name of the class in a string. So, for example, I can't figure out how to access BigSword.class with just the string "BigSword". From what I've read, this is referred to as Dynamic Class Loading, but I can't figure out how to implement it. One thing that makes it more difficult is that I need to send an argument to the class being loaded. I would really appreciate any help you all can provide. I've searched for online articles but have not found any helpful ones, so I'm hoping someone here knows how to do this. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I would use a 'Factory' for this. I would have a single class that contains a list of all classes that can be used. Within each of those classes I would have a "object getNewInstance();" and a "string getClassName();" method or perhaps just an if statement in the factory.

Share this post


Link to post
Share on other sites
Sounds like you're actually talking about Java - you should mention the language you're using when asking this sort of question. If it is Java you're using, there was recently a thread (in the Java forum) here on this sort of topic.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!