Hi. I am writing a library that will have the ability to access a server
by many different “transports” (JSON over HTTP, Thrift, etc). Depending
on which transport the user chooses, different files and classes will
need to be loaded.
A complete implementation of a transport requires that three classes
(such as the ‘Grid’ class below) be implemented from their respective
base class. Additionally, if the user wants to use JSON over HTTP, they
shouldn’t need to depend on the thrift gem and vice versa. These
transport classes are used by other classes within the library, and
should never be used directly by the user.
What is the best way to allow the user of the library to specify a
transport at runtime? Could I wrap all my implemented transport classes
in a module and do something like this?:
@t = transport
@grid = @t::Grid.new
where “transport” could be “MyProject::Transport::Thrift”.
Is this a good idea? Is there a better way?