On Sat, Dec 15, 2012 at 7:35 PM, Michael S. [email protected]
Allright, thanks robert. Its clear now how this attempt failed.
There was a working solution, where all references where class variables
of one big class. The constructors of all classes where unparameterized.
If a resource was needed, it was accessed through the big class. I
didn’t like this solution, because the classes where tightly coupled to
the big class. But it was a good thing, that exchanging one resource was
That sounds like the god object anti pattern. And it’s made worse by
the fact that the god object was not passed around but made accessible
like a global variable (the class instance in this case). That is
awful for testing.
Before that the circularly intertwined classes called each others
initialize in their constructors, where self had an adress already.
Worked. In my opinion it was the ultimate form of cuppling.
It’s difficult to properly evaluate that without more knowledge about
your use case. It does sound though that functionality might be
improperly distributed across classes if so many of them need to know
Now i have rather long parameterlists. I don’t like that either.
You can avoid that by grouping arguments into a class of its own. Of
course, that grouping must make sense. Often Struct can be used to
create such containers in a single like of code.
Another solution would be to use setter methods. But that would mean
writing a few lines of code per initialisation extra.
Or use Struct to create classes with a number of properties. You can
even add methods:
Window = Struct.new :width, :height, :pos_x, :pos_y do
screen.go_to pos_x, pos_y
The latter three solution also leave the question of globally exchanging
a resource open.
The circular reference must go. But this topic is interesting. What are
the established ways to treat circular references, long parameter lists
and globally used (and potentially variable) objects?
There is definitively not a one size fits all solution to get rid of
all three together. Even for individual items on your worklist
(circular refs, long parameter lists, global variables) there might be
As long as we do not know more about the nature of the application we
cannot really come up with good suggestions, I am afraid.