On Sat, Dec 15, 2012 at 7:35 PM, Michael Sas <[email protected]> wrote:
> Allright, thanks robert. Its clear now how this attempt failed.
Good!
> 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
> trivial.
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
each other.
> 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
def paint(screen)
screen.go_to pos_x, pos_y
screen.paint ...
end
end
> 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
multiple solutions.
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.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en