18 Feb '12, 12am

Issue 1.26: Structural Design Patterns (via Instapaper)

##Concrete Implementations class BasicTimeData def initialize(hour, minutes) @hour = hour @minutes = minutes end def formatted_output "Time is #{@hour}:#{@minutes}" end end class TimeWithMeridianData def initialize(hour, minutes, meridian) @hour = hour @minutes = minutes @meridian = meridian end def formatted_output "Time is #{@hour}:#{@minutes} #{@meridian}" end end ##Bridge module TimeFormatter def to_s @time_data.formatted_output end end ## Abstract Objects linked to Concrete Implementations through Bridge class BasicTime include TimeFormatter def initialize(*a, &b) @time_data = BasicTimeData.new(*a, &b) end end class TimeWithMeridian include TimeFormatter def initialize(*a, &b) @time_data = TimeWithMeridianData.new(*a, &b) end end ## Example Usage time1 = BasicTime.new("10","30") time2 = TimeWithMeridian.new("10","30","PM") [time1, time2].each { |t| puts t }

Full article: http://blog.rubybestpractices.com/posts/gregory/060-issue...


Creational Design Patterns in Ruby

blog.rubybestpractices.com 09 Feb '12, 4pm

This is a reasonable question to ask, because this approach is just as straightforward and has similar strengths and weakn...

Sold: School of Thought, Broader Perspectives 2...

secondhandbooks.com.sg 19 Feb '12, 4pm

Search Trends (Author / Title) RSS Feed (Last 50 books loaded)