-
Website
http://blog.new-bamboo.co.uk -
Original page
http://blog.new-bamboo.co.uk/2008/02/05/micro-patterns-in-ruby -
Subscribe
All Comments -
Community
-
Top Commenters
-
coupde
1 comment · 1 points
-
TomK32
1 comment · 1 points
-
prateekdayal
1 comment · 1 points
-
andycroll
1 comment · 1 points
-
drnic
1 comment · 6 points
-
-
Popular Threads
class ServiceParser
def register_adapter(url_matcher, adapter)
@@adapters[url_matcher] = adapter
end
end
class FlickrAdapter
# knows nothing about ServiceParser
end
class ServiceParser
def register_adapter(url_matcher, adapter)
@@adapters[url_matcher] = adapter
end
end
class FlickrAdapter
# knows nothing about ServiceParser
end
<pre>
</pre>class ServiceParser
def register_adapter(url_matcher, adapter)
@@adapters[url_matcher] = adapter
end
end
class FlickrAdapter
# knows nothing about ServiceParser
end
Yes, inheritance is probably misleading in my example, and it would certainly be an abuse if I was using ServiceParser only as a factory.
I actually based the examples on real code where ServiceParser has lots of private methods that are used by the subclasses. In my particular code, the parent class (ServiceParser) initializes with an instance of hPricot, which is available to all subclasses to use on their particular services, and some shared exception handling routines.
# Refactored factory. No pun intended.
did you mean
def self.initialize(url)
instead of
def self.instance(url)
?
That threw me for a minute.
SomeFactoryClass.instance( parameter) # => some instance of some class