问题描述
我正在尝试遵循 SOLID 概念,同时保持干燥(不要重复我自己)。
我有一个父类在它的子类之间共享一个方法,但是这个方法没有在父类本身中使用:
class ParentClass
def locals
{ id: ...,result: ... }
end
...
private
def method_used_in_descendants # this method is not used in ParentClass
end
end
class ChildClass < ParentClass
def locals
super.merge { whatever: method_used_in_descendants,one_result: ... }
end
...
end
class AnotherChildClass < ParentClass
def locals
super.merge { whatever: method_used_in_descendants,another_result: ... }
end
...
end
# And not all the descendants of ParentClass need method_used_in_descendants:
class AnotherChildClass < ParentClass
def locals
super.merge { whatever: my_private_method }
end
...
end
在 method_used_in_descendants
中创建的此方法 ParentClass
是不好的做法吗?
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)