From: Sys Ppp Date: 2009-08-27T06:32:05+09:00 Subject: Re: Rack must not dictate how to create a middleware Brian Candler wrote: > A middleware module must have a "next module" to pass the call() request > onto (otherwise it wouldn't be in the middle :-) So it makes sense to > create an instance of the middleware class, with the "next module" being > stored in an instance variable. Yes, I have caught sight of it. :) I just have noticed that Builder must not dictate way of creation each chained object. > The complicated bit is that Builder has to create them in a backwards > order so they wrap each other. Just little more complicated in realization. IMO it does not change fact of the matter. > I see you are using a module instance variable here. This is fine except > that it limits you to only using the same middleware once. Such is indeed I meant cases where middleware have to be a singleton. Or when mixing is intensively used instead of classes. In other cases surely using of classes is the best choice. Of course. But Builder must not make any limitations for using singletons or any "classless" objects there they are needed. > You may have a Rack setup which bundles multiple apps, e.g. using > urlmap, all of which are using the same middleware - in which case > you'll need multiple instances. Not doing this would severely limit the > flexibility of middleware IMO. There are some non-classic OOP paradigms, by the way intensively being used in Ruby, as I see. Such "classless" things as mixings, singletons, interfaces and so on. They are very useful, when the quantity of differences in object structures is near the quantity of these objects. On startup stages of project, when at the fist look it is very hard to deside which classes we have to make, but it is cleary known what kind of objects we are need. It especially relates to such muddy things as controllers in MVC pattern. And invoking of method :new inside Builder's :use - it is bad resctiction IMO. > No, you're free to create your own alternative Builder implementation. > After all, all it does is return an object which responds to #call. > That's all you need to do. It is very good. -- Posted via http://www.ruby-forum.com/.