Ruby is highly dynamic and extensible. Ruby is duck typed. Interface 
which is pervasive in Java is hard to see in Ruby. Thing changes. Many 
Gangof4 design patterns handle limitations of static languages like java 
and C++. So I think in Ruby, some design patterns become trivial or 
irrelevent , some can be simplified a lot.
Ruby is a fully object-oriented language. If we talk about OO, we surely 
concerns about design patterns.I think many of us want to see what 
happens to design patterns in ruby.
And I think the best way is to check the G4 design patterns one by one 
to see which one can be simplified , which one becomes trivial , or some 
new ones can be introduced.
Actually, I just think it is a good idea and I am not qualified to do 
that. But I think this community can do it. Anyone checks a pattern, 
then post his result here. We will soon get a revised version of design 
patterns in ruby.  It”Ēs attractive. I hope you are instrested , your 
attendance is highly appeciated.

And I will post one first, an abstract factory example, which can be 
simplified a lot as following. You can see, no inheritance tree needed.

class MacWindow
	def whoami; puts "A Mac window";end
end
class MotifWindow
	def whoami; puts "A Motif window";end
end
class MacScrollbar
	def whoami; puts "A Mac Scrollbar";end
end
class MotifScrollbar
	def whoami; puts "A Motif scrollbar";end
end
class WidgetFactory
	def initialize(winCls, scrollBarCls)
		@winCls = winCls
		@scrollBarCls = scrollBarCls
	end
	def makeWindow
		@winCls.new
	end
	def makeScrollBar
		@scrollBarCls.new
	end
end

def testWidgetFactory
	f = WidgetFactory.new(MotifWindow, MotifScrollbar)
	aWin = f.makeWindow
	aScrollBar = f.makeScrollBar
	aWin.whoami
	aScrollBar.whoami
	f = WidgetFactory.new(MacWindow, MacScrollbar)
	aWin = f.makeWindow
	aScrollBar = f.makeScrollBar
	aWin.whoami
	aScrollBar.whoami
end

testWidgetFactory

result:

A Motif window
A Motif scrollbar
A Mac window
A Mac Scrollbar

Best regards,

uncutstone

-- 
Posted via http://www.ruby-forum.com/.