Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 472789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:07:20+00:00 2026-05-13T00:07:20+00:00

Here is the problem, lets say we are making a video game and want

  • 0

Here is the problem, lets say we are making a video game and want to use Dependency Injection. Here is what we have:

Game Class  // This is just the code to keep track of the overall game logic
Character Class // This would be the guys in the game, good and bad guys both
Weapon Class // The weapons for the characters

So normally when I do Dependency Injection I would inject the current location on the maps, and game state into the character so my character would have the info to know where to create itself, etc. Then I have the character create the weapon and inject the values as to the strength of the weapons, as well as some other general game state from the Game Class etc.

This almost seems like an anti-pattern to me. I say that because now you have (at least it seems so to me) code that is very brittle and hard to change. If we want to change the game state information that is passed we are forced to change all three classes. We make the original change to the Game class, then modify Character and then finally modify the Weapon class as well. That is a lot of work especially if you are going 5 levels deep rather than just the 3 here. Though yes it would allow for easier Unit Tests than no DI.

This again sounds like bad practice. Is this the way things are typically done? What is we sort of had a ‘MotherShip’ pattern where everything is at the top level. So instead of game creates character creates weapon we let game (or some other class) create all of them.

This way if we wanted to add a new weapon to a character the game class could just create the weapon itself and inject it. Not sure what to do on this one. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:07:20+00:00Added an answer on May 13, 2026 at 12:07 am

    Design questions are tough to answer, especially when the example doesn’t seem to make sense. In this case, it makes not sense that a Character would create a Weapon. A character should be responsible for that one character. Maybe you can add a weapon to a character, but, unless the character is a weapons maker, I don’t think it would actually create a new Weapon class.

    BTW, I think a better pattern than either one of these would be the Factory pattern. Create a class who is responsible for creating weapons. And a class which is responsible for creating characters. That way, if there are 3 or 4 places which need to be changed when a character is created, that factory can handle that behavior and it is contained for future changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem. lets say I have a product category table and a
I have a question on making a good subquery for this problem Let's say
Lets say I have a core data model like this one: Item attributes: name
Can anybody help me with this? Here's the problem... When I have to code
Lets say I have a MovieClip called Box, and String is actually 'box' just
Here's a coding problem for those that like this kind of thing. Let's see
Just a small SVN problem here. I setup my own SVN server Setting up
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
I'm having a bit of a problem here. We have 2 urls let me
This is in reference to the question previously asked The problem here is, each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.