Code Smells @ YouTube
It’s great presentation which talks about refactoring the code by showing examples. The actual refactoring part is 20-minutes or something, but it has a lot of nice viewpoints. Defining the roles of modules and their interactions are the key factor of designing maintainable codes. Always, actual example-code works well understanding the concept.
One concern point (which I felt) is some of the classes are cross-communicating each other, making the class relationship a little complex.
- PushDaemon <-> UDPServer
- UDPServer <-> Client <-> Job
- Worker <-> Job
These classes are arbitrarily calling the other one’s method. As ruby’s duck typing doesn’t define the specific interface, it’s a little difficult to identify the method call-graph. Maybe, at least for the 1st item, instead of calling pre-fixed method each other, apply observer pattern (subscribe/notify) from one side makes it clear about their relationship?
require "observer" class Server include Observable def start sleep 1 changed notify_observers("sample response") end end class Daemon def initialize @server = Server.new @server.add_observer(self, :call) end def run @server.start end def call(message) puts "called by listener with message: " + message end end