Jump to content
  • Advertisement
Sign in to follow this  
sofakng

What's the proper way to share an object with several objects? (eg. a logging object)

This topic is 4833 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

This seems to be a stupid question but I'm a bit confused... (I'm using Delphi/Object Oriented Pascal) Right now I have my main form that creates an object of the class "TLog". Main also creates other objects (eg. TConnections, TPlayer) that I would like to use the log object I just created. Do I need to pass my already-created TLog object into every other object I create? It seems like there is a better way of doing it. Example: 1. My main form creates a TLog and a TConnections object. 2. My TConnections object creates a TPlayer object. 3. My TPlayer object creates a TDatabase object. Do I need pass my TLog object into TConnections and then have it pass it to my TPlayer object and then finally pass it to my TDatabase object? One solution I COULD do is create seperate log objects but that would prevent me from logging to the screen (eg. I have a memo box on my main form that displays logging information so my TConnections object has no idea about this unless I pass an already created log object)

Share this post


Link to post
Share on other sites
Advertisement
You're looking for a singleton class, just google for "singleton pattern" and you'll find thousands of results

Share this post


Link to post
Share on other sites
Ahh, ok. Thanks!

Let me ask another quick question because maybe I just have my logic all screwed up:

1) I have a main object which handles incoming socket connections, etc.
2) My main object creates a log object which handles all logging and debugging functions.
3) My main object creates a connections object which handles adding new connections to an array, etc.
4) My connections object creates player objects (as part of it's array) for each incoming socket connection.

Now here are two things I'm confused about...

Should I create a "processing" object to handle all gameplay related operations? If I do, this processing object will need a reference to my connections object which doesn't seem a good method to program...

Should I create a database object for each player? I'm thinking I should create another singleton (?) class so I only have one open database connection instead of 10+

[EDIT] Should maybe my connections object be a singleton too?

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!