Jump to content
  • Advertisement
Sign in to follow this  
graveyard filla

question about monostate pattern

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

hi, i've been reading up on the monostate pattern, but theres one thing i dont understand. what is the point in even instantiating an object at all? why not just make the functions static too? thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
It's a matter of perspective. The objects that use a monostate do not know it's a monostate. Thus allowing you to later change its implementation.

Share this post


Link to post
Share on other sites
In theory, by having the instantiated objects from the beginning, if you later change things so that it *isn't* a Monostate, you don't have to go around all the rest of the code changing static method calls to instantiate objects and make object method calls.

In practice, when you determine that you want different objects of the class, you're probably going to have to go around anyway to change *how* the objects are instantiated.

That is: if you cached stuff before to avoid writing "new Foo()." all over the place, then that caching may no longer be valid; conversely, you may need certain instances to be the same after the change, whereas it didn't matter before if you made a new Foo() each time (because of the Monostate-ness).

Share this post


Link to post
Share on other sites
Actually Zahlman, they shouldn't know that it is a monostate. If they do, then you have defeated the entire point of using a monostate and should just go ahead and straight out use a singleton.

Share this post


Link to post
Share on other sites
They shouldn't know, indeed, but I don't see what policy you use, in general, for creating the instances such that the code is resistant to a change away from (or towards?) Monostate-ness.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!