Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Well, to begin with, passing required objects into a constructor is a fine solution.

One alternative would be to use the Services architecture, which allows you to simply pass that around. It has some nice properties, but also makes things more complex. Take a look at this discussionthis discussion.

It is still passing stuff into a constructor - but at least there is less typing.

You could also consider making a custom "Game Screen Resources" class and pass that around. I think this is perhaps more appropriate than services, if you want to continue down this route.

But do not dismiss the idea of just making everything global. It's a game. It doesn't have to be an architectural delight.

Of particular note is Input - where the source data is already global (see XNA's Mouse, Keyboard, etc). Unless you are actually doing automated unit testing and actually need the ability to swap out implementations now, just go ahead and make your Input class a static class.

By the same token, you could make your SpriteBatch instance public (Content already is) and make your game class instance statically available (ie: global).

This is very good from a DTTSTCPW perspective. It's extremely easy, and can easily be modified later (with no more additional effort than implementing something more complicated in the first place).

(My answer here similar to this one and probably also worth reading.)

Well, to begin with, passing required objects into a constructor is a fine solution.

One alternative would be to use the Services architecture, which allows you to simply pass that around. It has some nice properties, but also makes things more complex. Take a look at this discussion.

It is still passing stuff into a constructor - but at least there is less typing.

You could also consider making a custom "Game Screen Resources" class and pass that around. I think this is perhaps more appropriate than services, if you want to continue down this route.

But do not dismiss the idea of just making everything global. It's a game. It doesn't have to be an architectural delight.

Of particular note is Input - where the source data is already global (see XNA's Mouse, Keyboard, etc). Unless you are actually doing automated unit testing and actually need the ability to swap out implementations now, just go ahead and make your Input class a static class.

By the same token, you could make your SpriteBatch instance public (Content already is) and make your game class instance statically available (ie: global).

This is very good from a DTTSTCPW perspective. It's extremely easy, and can easily be modified later (with no more additional effort than implementing something more complicated in the first place).

(My answer here similar to this one and probably also worth reading.)

Well, to begin with, passing required objects into a constructor is a fine solution.

One alternative would be to use the Services architecture, which allows you to simply pass that around. It has some nice properties, but also makes things more complex. Take a look at this discussion.

It is still passing stuff into a constructor - but at least there is less typing.

You could also consider making a custom "Game Screen Resources" class and pass that around. I think this is perhaps more appropriate than services, if you want to continue down this route.

But do not dismiss the idea of just making everything global. It's a game. It doesn't have to be an architectural delight.

Of particular note is Input - where the source data is already global (see XNA's Mouse, Keyboard, etc). Unless you are actually doing automated unit testing and actually need the ability to swap out implementations now, just go ahead and make your Input class a static class.

By the same token, you could make your SpriteBatch instance public (Content already is) and make your game class instance statically available (ie: global).

This is very good from a DTTSTCPW perspective. It's extremely easy, and can easily be modified later (with no more additional effort than implementing something more complicated in the first place).

(My answer here similar to this one and probably also worth reading.)

replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

Well, to begin with, passing required objects into a constructor is a fine solution.

One alternative would be to use the Services architecture, which allows you to simply pass that around. It has some nice properties, but also makes things more complex. Take a look at this discussion.

It is still passing stuff into a constructor - but at least there is less typing.

You could also consider making a custom "Game Screen Resources" class and pass that around. I think this is perhaps more appropriate than services, if you want to continue down this route.

But do not dismiss the idea of just making everything global. It's a game. It doesn't have to be an architectural delight.

Of particular note is Input - where the source data is already global (see XNA's Mouse, Keyboard, etc). Unless you are actually doing automated unit testing and actually need the ability to swap out implementations now, just go ahead and make your Input class a static class.

By the same token, you could make your SpriteBatch instance public (Content already is) and make your game class instance statically available (ie: global).

This is very good from a DTTSTCPW perspective. It's extremely easy, and can easily be modified later (with no more additional effort than implementing something more complicated in the first place).

(My answer hereMy answer here similar to this one and probably also worth reading.)

Well, to begin with, passing required objects into a constructor is a fine solution.

One alternative would be to use the Services architecture, which allows you to simply pass that around. It has some nice properties, but also makes things more complex. Take a look at this discussion.

It is still passing stuff into a constructor - but at least there is less typing.

You could also consider making a custom "Game Screen Resources" class and pass that around. I think this is perhaps more appropriate than services, if you want to continue down this route.

But do not dismiss the idea of just making everything global. It's a game. It doesn't have to be an architectural delight.

Of particular note is Input - where the source data is already global (see XNA's Mouse, Keyboard, etc). Unless you are actually doing automated unit testing and actually need the ability to swap out implementations now, just go ahead and make your Input class a static class.

By the same token, you could make your SpriteBatch instance public (Content already is) and make your game class instance statically available (ie: global).

This is very good from a DTTSTCPW perspective. It's extremely easy, and can easily be modified later (with no more additional effort than implementing something more complicated in the first place).

(My answer here similar to this one and probably also worth reading.)

Well, to begin with, passing required objects into a constructor is a fine solution.

One alternative would be to use the Services architecture, which allows you to simply pass that around. It has some nice properties, but also makes things more complex. Take a look at this discussion.

It is still passing stuff into a constructor - but at least there is less typing.

You could also consider making a custom "Game Screen Resources" class and pass that around. I think this is perhaps more appropriate than services, if you want to continue down this route.

But do not dismiss the idea of just making everything global. It's a game. It doesn't have to be an architectural delight.

Of particular note is Input - where the source data is already global (see XNA's Mouse, Keyboard, etc). Unless you are actually doing automated unit testing and actually need the ability to swap out implementations now, just go ahead and make your Input class a static class.

By the same token, you could make your SpriteBatch instance public (Content already is) and make your game class instance statically available (ie: global).

This is very good from a DTTSTCPW perspective. It's extremely easy, and can easily be modified later (with no more additional effort than implementing something more complicated in the first place).

(My answer here similar to this one and probably also worth reading.)

Source Link
Andrew Russell
  • 21.3k
  • 7
  • 58
  • 104

Well, to begin with, passing required objects into a constructor is a fine solution.

One alternative would be to use the Services architecture, which allows you to simply pass that around. It has some nice properties, but also makes things more complex. Take a look at this discussion.

It is still passing stuff into a constructor - but at least there is less typing.

You could also consider making a custom "Game Screen Resources" class and pass that around. I think this is perhaps more appropriate than services, if you want to continue down this route.

But do not dismiss the idea of just making everything global. It's a game. It doesn't have to be an architectural delight.

Of particular note is Input - where the source data is already global (see XNA's Mouse, Keyboard, etc). Unless you are actually doing automated unit testing and actually need the ability to swap out implementations now, just go ahead and make your Input class a static class.

By the same token, you could make your SpriteBatch instance public (Content already is) and make your game class instance statically available (ie: global).

This is very good from a DTTSTCPW perspective. It's extremely easy, and can easily be modified later (with no more additional effort than implementing something more complicated in the first place).

(My answer here similar to this one and probably also worth reading.)