Given some Uploader Class, I have three modules included in it.
They have each their own distinctive uses and that's why I divided them into three modules. But, as it turns out, there is one method that all three modules need.
So, it is so far obvious to me that there must be a better way than defining this method in each of these three modules. Should I make a fourth module and put 开发者_如何学编程this method in it, and have these original three modules include this fourth module? Or is there a better way?
Yes, it sounds like you should have a fourth module. But it sounds like you might actually need a class hierarchy rather than independent, flat modules. Apply the 'is a' test - can you say an UploaderA instance is an Uploader? If so, you should have
class Uploader
include FourthModule # with shared functionality for all uploaders
# or just go ahead and put the shared functionality right in the Uploader class here.
end
class UploaderA < Uploader
end
精彩评论