Extreme isolation in web apps
chrismdp.com
Extreme isolation in web apps
1–7 of 7 posts
Re: Extreme isolation in web apps
#2 class JoiningError Re: Extreme isolation in web apps
#3This must be the Ruby equivalent of the once prevalent Java pattern craze, I mean what the hell is the purpose of a class like this: class JoiningError
case(change.class)
when JoiningError:
joining_error()
when SomethingElse:
something_else()
...
end
It's actually not implemented like that under the hood: it's done using a module with a `send`.Re: Extreme isolation in web apps
#4This must be the Ruby equivalent of the once prevalent Java pattern craze, I mean what the hell is the purpose of a class like this: class JoiningError
The purpose is to avoid a big case statement: case(change.class) when JoiningError: joining_error() when SomethingElse: something_else() ... end It's actually not implemented like that under the hood: it's done using a module with a `send`.
post '/join/?' do
game_server = GameServer.instance
if game_server.join(params[:name], @account.id)
flash[:notice] = "You have joined the game."
redirect_to '/game'
else
flash[:error] = "There was an error when joining: #{change.message}"
haml :join
end
end
class GameServer
include Singleton
def initialize
@games = [Game.new]
end
def join(name, account_id)
player = Player.new(name, account_id)
return @games.last.joined_by(player)
end
end
class Player
Could you explain to me how is the version presented an improvement over such a straightforward one?Re: Extreme isolation in web apps
#5Earlier quoted context omitted.
The purpose is to avoid a big case statement: case(change.class) when JoiningError: joining_error() when SomethingElse: something_else() ... end It's actually not implemented like that under the hood: it's done using a module with a `send`.
I don't get it at all. Here is the whole thing in straightforward 80's OOP: post '/join/?' do game_server = GameServer.instance if game_server.join(params[:name], @account.id) flash[:notice] = "You have joined the game." redirect_to '/game' else flash[:error] = "There was an error when joining: #{change.message}" haml :join end end class GameServer include Singleton def initialize @games = [Game.new] end def join(nam…
Re: Extreme isolation in web apps
#6Earlier quoted context omitted.
I don't get it at all. Here is the whole thing in straightforward 80's OOP: post '/join/?' do game_server = GameServer.instance if game_server.join(params[:name], @account.id) flash[:notice] = "You have joined the game." redirect_to '/game' else flash[:error] = "There was an error when joining: #{change.message}" haml :join end end class GameServer include Singleton def initialize @games = [Game.new] end def join(nam…
There's no persistence in your example: how would you plug that in?
Re: Extreme isolation in web apps
#7Earlier quoted context omitted.
There's no persistence in your example: how would you plug that in?
If I would see any purpose in striving for this level of separation I would use the DataMapper pattern ( http://martinfowler.com/eaaCatalog/dataMapper.html ), but I do not see it, so the Player etc. models would probably be ActiveRecords.