使用小部件标题属性引用它会被认为是一种坏做法吗?
例如,我有一些自定义
radioBoxCtrls
在一
panel
我只需要一次获取/设置所有值
所以容器类(一个面板)
放射性核素CTRLS
对象有以下方法
get_options()
set_options()
为所有
放射性核素CTRLS
一
dictionary
传递给
set_options()
方法。
各
key
,
value
字典中的对是
title
A的
radioBoxCtrl
以及
标题
的
button
上
放射性核素CTRL
应该设置的
def set_options(self, options={}):
"""
This method sets which radio button is selected
on each RadioBoxCtrl object
@param options: A dictionary
Each key is the title of a RadioBoxCtrl
each keys value is the button on the radio box that is to be selected
"""
for option_box in self.option_boxes:
if option_box.title in options.keys()
option_box.set_selected_button(options[option_box.title])
def get_options(self):
"""
This method returns a dictionary of the selected options
Each key is the title of a RadioBoxCtrl object
and each keys value is the name of the button selected on the radio box
"""
options = defaultdict(list)
for option_box in self.option_boxes:
options[option_box.title]=option_box.get_selected_btn()
return options
当我从控制器调用set方法时
我交了一本字典,就像这样:
options = {"Name of radioBoxCtrl": "Option 2", ... }
self.gui.optionsPanel.set_options(options)
你为什么要那样做?
(你可能会问)
简短回答
:
MVC
我想创建一个合适的抽象层。所有我的控制器需要知道的
关于这些选项是如何让它们在需要进行某些处理时传递到模型,以及在加载配置文件时如何设置它们…
我以为只要调用一个方法来设置它就能简化事情,反之亦然——但我现在还不确定!
我认识到,这可能是关于通过对象所拥有的某些字符串属性引用对象的可接受性的更多问题,在我的例子中,恰好是标题。所以请随意回答。
请随时改进问题的标题(我真的不知道怎么说)并添加标签。
谢谢