Robert Klemme wrote:
> 2006/5/18, uncutstone wu <uncutstone / sina.com>:
>> 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.
> 
> That might be an interesting thing to do.
> 
>> simplified a lot as following. You can see, no inheritance tree needed.
> <snip/>
> 
> IMHO you don't even need a separate class.  Every object that
> implements #new is a factory, especially every class object is.  So
> storing an object somewhere and requiring that it implements new
> without args is enough.
> 

Yes, you are right. Class WidegetFactory is unnecessary. So an simpler 
version is:
class MacWindow
	def whoami; puts "A Mac window";end
end
class MotifWindow
	def whoami; puts "A Motif window";end
end

def testAbstractFactory
	aWinFactory = MotifWindow
	aWin = aWinFactory.new
	aWin.whoami
end

testAbstractFactory

result:
A Motif window

In fact, as the code shows, in ruby, abstract factory pattern 
disappears, since a pattern always means a group of collaborative 
classes or objects. I really think ruby is a magic language.

Best regards,

uncutstone


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