views:

110

answers:

2

Do Ruby on Rails' ActiveRecord dynamic finders have a problem in that they don't explicitly tell clients about their interface?

Clients = client code or developers creating the client code. What uses the ActiveRecord. If you use the active record, is it clear from looking at the class what you can do with it, what it needs or how you can work with it (=interface).

Hope this clears things up. Formulation was confusing I agree.

A: 

I think the only question is whether you have a problem with the lack of an explicit interface. If you want to go write

def find_by_name
  ...
end
def find_all_by_name
  ...
end

and all the rest of them there's nothing stopping you from making them explicit. I think you'll find that while theoretically confusing, in practice it's no big deal. The ActiveRecord contract is pretty easy to remember.

jdwyah
It's easy to remember and maybe practical. But is it also against good OO practice?
koen
A: 

If I understand your (obscured) question correctly, there is no lying involved.

Given: eg an ActiveRecord called: Order with attribute "name" try this:

>> Order.respond_to? :find_by_name
=> true
Taryn East