The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Even better…

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jamis Buck

Posts: 184
Nickname: minam
Registered: Oct, 2004

Jamis Buck is a C/Java software developer for BYU, and hacks in Ruby for fun.
Even better… Posted: Nov 14, 2004 8:26 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jamis Buck.
Original Post: Even better…
Feed Title: the buckblogs here
Feed URL: http://weblog.jamisbuck.org/blog.cgi/programming/index.rss
Feed Description: Jamis Buck's corner of the blogging universe. Mostly about ruby, but includes ramblings on a variety of topics.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jamis Buck
Latest Posts From the buckblogs here

Advertisement

Perhaps you’ve already read my last article, Now that’s cool, in which I described a way of doing parameterized services with Needle. If you have, go ahead and forget everything it mentioned. The next version of Needle (v1.2, to be released this Thursday) has a better way.

As a result of discussions with Christian Neukirchen and Joel VanderWerf, I finally sat down and attempted to find a way to support parameterized services. If you missed my last article, parameterized services are just services that require contextual information to be given to them in order to instantiate them. Thus, you can’t really have parameterized singleton services (since singleton’s are only instantiated once), but for prototype services, it would be a real boon.

Joel also suggested multitons, which are like singletons except that they are parameterized, and they return a unique object instance for each unique parameter set. A kind of cross between prototypes and singletons.

It turned out to be almost embarassingly easy to implement both of these features. The next version of Needle will support a :multiton service model, and parameterized services. Observe:

  registry.define.printers( :model => :multiton ) { |c,p,name| Printer.new( name ) }
  mono = registry.printers( :monochrome )
  color = registry.printers( :color )
  ...

(Note that the c and p parameters are required—the first is the container that the service belongs to, and the second is the service point instance that represents the service. You use the c parameter to access other services, and the p parameter to get metadata about the current service, like fullname. The remaining parameters are contextual, given when requesting the service.)

Much nicer than the trick I demonstrated using lambda services. Although I still think lambda services are pretty slick…I imagine they may even still be useful, though I haven’t had a chance to think too much about that.

Read: Even better…

Topic: Collaboraid puts large NGO on Rails Previous Topic   Next Topic Topic: The recurring misguided desire for components

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use