Hi all,
I want to implement the concept of a Workspace. This is a global concept - all other code will interact with one instance of this Workspace. The Workspace will be responsible for maintaining the current system state (i.e. interacting with the system model, persisting the system state etc)
So what's the best design strategy for my Workspace, bearing in mind this will have to be testable (using RSpec now, but happy to look at alternatives).
Having read thru some open source projects out there and I've seen 3 strategies. None of which I can identify as "the best practice".
They are:
- Include the
singleton
class. But how testable is this? Will the global state of Workspace change between tests? - Implemented all behaviour as class methods. Again how do you test this?
- Implemented all behaviour as module methods. Not sure about this one at all!
Which is best? Or is there another way?
Thanks, Gordon
Edit
As I started including the 'singleton' module in all my code and I realised just how tightly coupled I had made my code, with references to these global instances all over the place.
So I've started to remove them entirely and pass references to the global instances instead. But now I'm heading down the route of IOC - passing dependencies down through my constructers.
Is this a good idea in Ruby? Or am I missing something?
BTW you may have gathered I'm new to Ruby!