gene.tani / gmail.com wrote: > uncutstone wu wrote: > >> 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. >> > > http://www.rubygarden.org/ruby?ExampleDesignPatternsInRuby > http://raa.ruby-lang.org/cat.rhtml?>category_major=Library;category_minor=Design%20Patterns Acctually, I did took a look at ExampleDesignPatternsInRuby before. But after read the first one , abstract factory, I am skeptical of its quality. I quoted the code and the explanation the author made below and I will explain my view. >class Foo; end >class Bar; end > ># Here is the use of the Abstract Factory pattern > >def create_something( factory ) >new_object = factory.new >puts "created a new #{new_object.class} with a factory" >end ># Here we select a factory to use >create_something( Foo ) >create_something( Bar ) >Running the code above results in the output: >created a Foo with a factory >created a Bar with a factory > > >Q: Ummm. Seems to me that you're specifying the concrete class name here: create_something(Foo) and >create_something(Bar). My understanding of Abstract Factory is that there's an additional level of I>ndirection involved. >A: The create_something method is creating objects through an abstract interface and does not have >knowledge of concrete types. >The code at the top level is selecting which factory object will be used by create_something. There always >needs to be some part of >the code that creates factories, and that part needs knowledge of concrete types. The use of the >Abstract Factory method is to shield >the rest of the code from that knowledge. I fully don¡Çt agree with the author¡Çs opinion. I think what abstract factory does is to shield clients who need create object from the object¡Çs concrete type, but not to shield the abstract factory itself from concrete type. Acctually ,abstract factory will have the knowledge of the concrete type and shield the client of abstract factory from the concrete type . But what the code does is opposite. The abstract factory(here is create_something) does¡Çt know concrete type, and the client will give that info to it every time the client need a object. It¡Çs toally misunderstanding of abstract factory. Since the first pattern example in the article is really bad , I am skeptical of its quality. So I think we need redo the work. That is why I post this message. Best regards, uncutstone -- Posted via http://www.ruby-forum.com/.