From: Dimitri Aivaliotis Date: 2006-03-23T14:43:24+09:00 Subject: Re: [QUIZ] Space Merchant (#71) I know this is 11th-hour and all, but I thought I'd mention it anyways. When I read this quiz, I immediately thought of using a Dependency Injection framework to solve it. I also wanted to add elements of the Firefly `Verse to the gameplay, so I'd describe it in a YAML file. Unfortunately, I haven't had the time to do more than just a mock-up: registry = Needle::Registry.new do |reg| reg.register( :galaxy ) { Galaxy.new( 'firefly.yaml' ) } reg.intercept( :galaxy ).with! { logging_interceptor } reg.register( :sector, :model => :multiton ) do |c,p,name,location| Sector.new( name, location ) end reg.intercept( :sector ).with! { logging_interceptor } reg.register( :planet, :model => :multiton ) do |c,p,name,sector| Planet.new( name, sector ) end reg.intercept( :planet ).with! { logging_interceptor } reg.register( :station, :model => :multiton ) do |c,p,name,sector| Station.new( name, sector ) end reg.intercept( :station ).with! { logging_interceptor } reg.register( :player, :model => :multiton ) do |c,p,name| Player.new( name ) end reg.intercept( :player ).with! { logging_interceptor } end galaxy = registry.galaxy firefly.yaml (partial): --- galaxy: firefly player: credits : 1000 reputation : 100 sectors: - name : 1 location : central planets: - name : Ariel description : "Planet. Home to a major medical center, Saint Lucy's." - name : 2 location : central planets: - name : Persephone description : Planet. Heavily stratified societal structure. Resupply port for Serenity. I had envisioned this as a webapp, where players could register and all play within the same universe. The Authenticator and Presenter aren't shown above. Each player would then be instatiated like so: = registry.player("") They could save the game state to a YAML file, which would then be transportable across SpaceMerchant implementations. So, what do you all think? Anybody with actual DI/IoC experience care to chime in? (As you can probably tell, this would be my first time using DI.) Are there any other Browncoats out there? Could this maybe be a Part 2 to this quiz? - Dimitri