Tuesday, October 17, 2006

Dependency Inversion conversation with Jamis Buck

This conversation represents the sort of headache/transition in getting out of the strict OO mindset and contract-based programming that Ruby allows you to intuitively avoid:

(14:45:35) russ: if you have a minute, gotta design question for you. I have an authentication component that I'd like to turn into a service so it's interchangeable ala Hivemind. Would you recommend copland for doing that? At this point I only have two implementations of the service, but it makes sense to have more in the future...
(14:45:59) jamisbuck: for ruby, I'd avoid DI implementations as a general rule
(14:46:03) jamisbuck: ruby is flexible enough that you don't need them
(14:46:11) russ: the alternative I could think of would be to create some sort of abstract base class and then extend as needed...though not sure how that would fit into Ruby's methodology
(14:46:32) russ: I'm still stuck in j2ee thinking
(14:46:40) jamisbuck: :) it took me two years to come around :)
(14:46:49) russ: so recommendations for my issue?
(14:47:02) jamisbuck: well, you could use a factory class
(14:47:10) russ: two different classes, rely on some static class and put the logic in there to call the appropriately underlying?
(14:47:11) jamisbuck: Foo.authentication_service
(14:47:18) jamisbuck: sure
(14:47:26) jamisbuck: without knowing all the details that sounds fine
(14:47:30) jamisbuck: there may be an even simpler way to do it
(14:47:39) russ: my problem is contracts: interfaces/abstract base classes
(14:47:52) russ: how to move away from that yet make the Ruby code solid
(14:47:54) jamisbuck: careful not to overthink the problem
(14:48:01) jamisbuck: ruby encourages pragmatic solutions
(14:48:20) jamisbuck: I know that when I was coming out of Javaland, I would frequently overlook the simple solutions because they were so simple :)
(14:48:27) jamisbuck: that's not to say every problem has a simple solution
(14:48:40) russ: indeed
(14:48:49) russ: as usual, your feedback is highly valuable
(14:48:52) russ: thanks Jamis!
(14:48:53) russ: have a good one
(14:48:56) jamisbuck: :) you too!

No comments: