From: Daniel Baird Date: 2006-03-22T18:34:58+09:00 Subject: Re: Is this a kind of design patterns? ------=_Part_2518_33203729.1143020081342 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The truth is, as a ganeral rule the original G4 design patterns were kinda statically-typed-language-centric, so it wouldn't surprise me if there was some small details in Ruby versions of the patterns that didn't quite fit the "classic" description. In this case though, it does look a lot like the Factory pattern, apart fro= m new still being available. I think if Color.new was re-declared as private= , that would make it a textbook case of the Factory pattern. IANA(language)L though.. ;Daniel On 22/03/06, killy-kun wrote: > > Sam Kong wrote: > > Hi! > > > > Sometimes a class provides object instantiation methods other than new. > > See an example. > > > > class Color > > def initialize r, g, b > > @r =3D r > > @g =3D g > > @b =3D b > > end > > > > def to_s > > "R: #{@r}, G: #{@g}, B: #{@b}" > > end > > > > class << self > > def red > > new 255, 0, 0 > > end > > > > def blue > > new 0, 0, 255 > > end > > > > def green > > new 0, 255, 0 > > end > > end > > end > > > > puts Color.new(100, 120, 140) > > puts Color.red > > puts Color.blue > > > > > > Is this one of design patterns, or just a simple idiom? > > It's similar to a factory method pattern but it's not according to the > > definition. > > Is there any name for it? > > > > TIA. > > > > Sam > > > > isn't that the facory design pattern ? > > -- Daniel Baird http://danielbaird.com (TiddlyW;nks! :: Whiteboard Koala :: Blog :: Things That Suck) [[My webhost uptime is ~ 92%.. if no answer pls call again later!]] ------=_Part_2518_33203729.1143020081342--