I am asking for help regarding a design pattern. I am very used to interfaces in java, and I dont know how to get a similar mechanism in ruby. What it need is kind of interface which has a method e.g. contacts. In order to get contacts I need to make a call against an api, this could be google, linkedid or whatever webservice. So I d like to use an interface which provides me the contacts method and i dont want to know anything about the provider beyond.
My first attempt looks like this (pseudo code):
Module AbstractContact
def contacts
#do some stuff with @data
@data
end
end
class Impl
include AbstractContact
def build_provider(provider)
if provider == :google
#get the data from google
gdata= api_call
@data = gdata
elsif provider == :linkedin
end
end
end
c=Impl.new
c.build_provider
c.contacts
But I am really not sure, if this is the "ruby way to go".
Help, suggestions and recommendations are welcome. Best, Phil