background preloader

Factory

Facebook Twitter

Factory method pattern. Factory method pattern in UML Definition[edit] The essence of this pattern is to "Define an interface for creating an object, but let the classes that implement the interface decide which class to instantiate.

Factory method pattern

The Factory method lets a class defer instantiation to subclasses. Overview of Factory Method Pattern. Factory methods in Ruby. Re: Factory Patterns in Ruby. Design Patterns in Ruby : The Factory Method. This is an article series on implementing programming Design Patterns in Ruby. This is the second part of the series and here’s a link to the last article on the Template Design Pattern. The Factory Method Pattern I have to this say this, but Wikipedia has a pretty good explanation and a Ruby implementation for this Creational Pattern, so I’d be focusing mainly upon the general idea of why this pattern is similar to the Template Method pattern and explain some of its defined variants. More precisely, the Shape module is for defining the Draw method which raises a predefined NotImplementedError exception object. Circle, Square and Tetrahedron are the subclasses which call the Shape module and are called by the Factory Method – CallShapes for creating objects out of them to be selected as per the user call.