你认为这是我应该遵循的策略,还是我能以更好的方式做到这一点?
答案 0 :(得分:1)
我想说你应该创建一个可以继承或包含在Person和Monster类中的Combatant类或模块,但是你不应该将多态关联保存到数据库中。你应该只使用两个表:人和怪物。
module Combatant ... end class Person < ActiveRecord::Base include Combatant ... end class Monster < ActiveRecord::Base include Combatant ... end
答案 1 :(得分:0)
另一个选项是Single Table Inheritance
class Combatant < ActiveRecord::Base
# Has all the fields we care about and basic damage rules, etc
end
class Person < Combatant
# Any functions that only players can do
end
class Monster < Combatant
# any functions that need to be overridden
end