| The services receive messages from the router, then send messages to whatever they need to call to get the job done. Being sent messages by the framework is what makes it a framework and not a library; I don't get your objection here. If it was a framework modelled in an object oriented way it would itself be built of classes exchanging messages, but it isn't. It encourages you to also structure your code in a non object oriented way by creating hundreds of little services which are basically procedure calls instead of making your model accept a wider variety of messages or instead of building classes with more than just a "call" method. Most of the code is supposed to go directly into the services, that's the whole point of the framework, remember it is a solution to the "fat model" problem: One in particular is something I've been thinking about and refining for a while now [3]. In this approach, persistence objects remain extremely thin, and business logic is encapsulated in lots of very simple objects known as “services” and “policies”. Also, keep in mind that the services do not normally call each other (they could in theory, but that would be even more awkward), so instead of having message exchange between models you have duplicated code in services or have to use inheritance. Ruby is object oriented so sure there are message calls further down, it doesn't make the framework object oriented on the logical level. Only if you're conflating domain objects with persistence objects. Must you go as far as to refer to a hypothetical reality just to win an argument ;) ? That's how Rails works, that's what the examples show, I am not referring to what is possible in theory, but to what the framework does and the most reasonable possible way of using it. Honestly one more level of indirection would make this look completely ridiculous. They're statically dispatched on a constant name, not on a class. If you need polymorphism at that point, it's trivial to define a dynamic service resolver - all you need is something with a #new method assigned to the constant to do whatever late binding you want. Ehm, no? You cannot just define a "new" method returning whatever you want neither in a module nor in a class in Ruby. You would have to overwrite the initialization methods that are usually hidden from the user. Passing a constant name is almost equivalent to passing a class. module Foo
def new
5
end
end
puts Foo.new.inspect
# undefined method `new' for Foo:Module (NoMethodError)
class Bar
def new
5
end
end
puts Bar.new.inspect
# #<Bar:0xa146324>
|
Eh? The sentence you quoted explains that putting domain logic in the persistence objects is precisely what objectify avoids. I do't see any examples of domain logic as separate from persistence logic at all in the examples, so I'm not sure where you're getting the idea that the framework encourages it from. If you're that tied to "how Rails works", why are we even discussing this? Objectify exists to change the way Rails works, because the way Rails works is broken.
> Ehm, no?
Ehm, yes.