John D. wrote in post #1072359:
hostname = WebProperty.new ‘www.yahoo.com’
HTTP doesn’t have a “lookup” operation, so do you mean something like
This is the typical OO conundrum. For a method which takes two object
arguments, which class does the logic belong to?
If there is no polymorphism involved then it doesn’t really matter, and
in this case arguably it doesn’t belong to either:
Or maybe the logic belongs in a URI object.
One advantage of your approach is that hostname.HTTP could keep track of
a persistent HTTP connection, so that a series of hostname.HTTP.get()
operations would re-use the same connection.
My natural inclination would be instead to have a “HTTP fetcher” class:
this is not too dissimilar, but it makes it more obvious how to set
options which are specific to the HTTP connection, rather than to the
thing you’re connecting to. (Timeouts, for example).
http1 = HTTP.new :hostname=>‘www.google.com’,
http2 = HTTP.new :hostname=>‘www.yahoo.com’,
yahoo = http1.get ‘/index.html’
google = http2.get ‘/index.html’
This approach is also arguably more pluggable.
But this is entirely subjective: hostname.HTTP.get(path) will obviously
work, and if it makes sense for your particular application, then by all
means use it.