class Stuff
attr_accessor :config
attr_accessor :dbh
attr_accessor :logger
def command_do_job_1
end
def command_do_job_2
end
def command_do_job...n
end
我知道,这不是一个合适的命令模式
接下来的问题是,每个命令都需要
1. Configuration
1. Logger
1. Set of parameters
n. database handles
m. supporting methods/functions
好吧,现在我不高兴了,因为如果我把命令放到适当的对象中,那么我会创建很多配置条目、参数、句柄,还有很多支持方法/函数,我想为不同的命令重复使用!
这样做也很有趣:
class Stuff
attr_accessor :dbh, :logger, :config
end
class Command
attr_accessor :parent
def initialize(parent)
@parent = parent
end
def config
@parent.config
end
ad-nausiem for logger, dbh, other "joint" resources etc...
end
stuff = Stuff.new
cmd = Command.new stuff
因此,如果我将“commands”分解成适当的对象并正确地执行,我就必须生成某种“framework/services”来执行中的命令,并提供、logger、dbh、config等。。
诗句
什么样的代码结构能让我更好地使用“资源/方法/函数”,同时又能让我的代码保持简洁?
这也不是什么大计划。。。
-丹尼尔