Topic: "Multiple Inheritance" (mixins) and WebServices

My team has finally hammered out a web service API for our current project. Looking at the API needs it appears to me that a multiple inheritance model is appropriate and it will really help us divide-and-conquer as we actually implement the API.

In broad terms (damn NDA) we want to provide a generic version of our webservice that can be used to accomplish every task that connecting systems will need to do. We also know that we will see some performance improvements if we extend that base service with a version for each connecting system to offer some convienience classes. No problems there, that is a matter of single inheritance which is supported.

Where we would see an improvement with multiple inheritance is in creating, for example, a User Authentication webservice and a User Modification webservice and then having our Base webservice inhert from each of those. That would allow one member of the dev team to work on a smaller webservice, keep things modular, and make maintenance easier. Psuedo-code for .NET/Java would look kind of like this:

MyGenricWebService inherits from MyUserAuthWebService, MyUserModWebService
{
authuser(login, pass)
....
newemail(userid, newemailaddr)
...
}

MySpecificWebService inherits from MyGenericWebservice
{
one_call_new_email(login, pass, newemailaddr)
}


I understand that Ruby provides something similar to multiple inheritance via mixin modules. I have looked at examples and it appears that if I define a method in a module and then mix it in, my class then exposes the constants and methods in that module as its own. Is this correct?

If I create methods in a module and then include that module in a WebService based class will those module methods also be exposed as WebService methods? As SOAP methods able to generate a proper WSDL?

Pseudo-code for what I want from rails

class MyGenericWebservice < ActionWebService::Base
include 'MyUserAuthMixIn'
include 'MyUserModMixIn'

def some_generic_method
  ...
end
end

class MySpecificWebService < MyGenericWebService
def some_specific_method
  ...
end
end


Would I be able to make SOAP calls to MySpecificWebService.my_generic_method as well as MySpecificWebService.some_method_in_user_auth_mixin?

Thanks for your help! I'm coming from a Java/.NET/PHP background and I'm still being retrained to trust the RoR framework to do the right thing! big_smile

Re: "Multiple Inheritance" (mixins) and WebServices

jbartels wrote:

Would I be able to make SOAP calls to MySpecificWebService.my_generic_method as well as MySpecificWebService.some_method_in_user_auth_mixin?

Yep, methods defined in modules are inherited by subclasses just like normal methods.

Railscasts - Free Ruby on Rails Screencasts

Re: "Multiple Inheritance" (mixins) and WebServices

Excellent.

Thanks ryanb!

Re: "Multiple Inheritance" (mixins) and WebServices

BTW, try out IRB (run "irb" in the command line). This is a great way to test out stuff like this:

module X
  def foo
    puts 'foo'
  end
end

class A
  include X
end

class B < A
end

B.new.foo # prints "foo"

Railscasts - Free Ruby on Rails Screencasts