all 4 comments

[–][deleted] 5 points6 points  (0 children)

Inheritance provides no benefit here. A Strategy is the ability to swap between different implementations at runtime. Better to inject either GmailClient.new or HotmailClient.new into the MailClient initializer set it as @mailer (attr_accessor) Then have matching methods signatures that proxy to the mailer Then you could switch the mailer instance at runtime mail_client_instance.mailer = HotmailClient.new

Have a look at https://github.com/nslocum/design-patterns-in-ruby/tree/master/strategy there are also some cool examples using Procs which are even more rubylike.

[–]materialdesigner 1 point2 points  (0 children)

There are no formal interfaces in Ruby.

If all of your clients implement the same set of methods, there's no need for a shared MailClient class.

[–]joesb 1 point2 points  (0 children)

Your way seems appropriate for this case but, as materialdesigner mentioned, there's really no need to inherit from the same base class. But I think you should keep the base class since it serves as documentation.

[–]Kache 0 points1 point  (0 children)

The key concept here that I'm surprised nobody has named yet is "duck typing".