Terrence Brannon
2015-04-29 16:44:58 UTC
As you can see in this code:
https://gist.github.com/metaperl/7d3512946a11ffcb110f
The business objects classes form an inheritance tree:
- CustomRows IS-A BodyKeyValue
- BodyKeyValue IS-A BodyText
- BodyText IS-A core python object
However, the editors for these classes inherit only form
nagare.editor.Editor. Why is this? Because if they did not, then the
line:
def __init__(self, target):
super(BodyTextEditor, self).__init__(target, self.fields)
would try to call the entire hierarchy of editors and the fields in
each would not get init'ed properly.
In other words, if you notice BodyTextEditor has these fields:
fields = 'name parser_type key tag_name'.split()
and it's "derived class" CustomRowEditor has these fields:
fields = 'name parser_type key row_delimiter value_type tag_name
key_position eol'.split()
I said "derived class" because it is not derived in the code. it is
not derived in the code, even though it would be nice if the
derived class did not have to repeat the common fields between
BodyTextEditor and CustomRowEditor.
Maybe it would be best if fields were build using inheritance like so:
class BodyKeyValueEditor(BodyTextEditor):
def build_fields(self):
super(BodyKeyValueEditor, self).build_fields
self.fields.append(my_special_fields)
class CustomRowEditor(BodyKeyValueEditor):
fields = list()
def __init__(self, target):
self.build_fields
super(CustomRowEditor, self).__init__(target, self.fields)
def build_fields(self):
super(CustomRowEditor, self).build_fields
self.fields.append(my_special_fields)
But then we still have the issue of binding the fields in the editor
to the fields in the target. This line will now fail:
super(CustomRowEditor, self).__init__(target, self.fields)
And needs to be repliaced with an explicit call to
editor.Editor.__init__ .. is that even possible?
So what do you think about using inheritance to build up the fields in
related edtiors? what would be your approach to:
1 - building such fields leveraging inheritance.
2 - __init__(target,self.fields)
3 - .commit(self.fields)
https://gist.github.com/metaperl/7d3512946a11ffcb110f
The business objects classes form an inheritance tree:
- CustomRows IS-A BodyKeyValue
- BodyKeyValue IS-A BodyText
- BodyText IS-A core python object
However, the editors for these classes inherit only form
nagare.editor.Editor. Why is this? Because if they did not, then the
line:
def __init__(self, target):
super(BodyTextEditor, self).__init__(target, self.fields)
would try to call the entire hierarchy of editors and the fields in
each would not get init'ed properly.
In other words, if you notice BodyTextEditor has these fields:
fields = 'name parser_type key tag_name'.split()
and it's "derived class" CustomRowEditor has these fields:
fields = 'name parser_type key row_delimiter value_type tag_name
key_position eol'.split()
I said "derived class" because it is not derived in the code. it is
not derived in the code, even though it would be nice if the
derived class did not have to repeat the common fields between
BodyTextEditor and CustomRowEditor.
Maybe it would be best if fields were build using inheritance like so:
class BodyKeyValueEditor(BodyTextEditor):
def build_fields(self):
super(BodyKeyValueEditor, self).build_fields
self.fields.append(my_special_fields)
class CustomRowEditor(BodyKeyValueEditor):
fields = list()
def __init__(self, target):
self.build_fields
super(CustomRowEditor, self).__init__(target, self.fields)
def build_fields(self):
super(CustomRowEditor, self).build_fields
self.fields.append(my_special_fields)
But then we still have the issue of binding the fields in the editor
to the fields in the target. This line will now fail:
super(CustomRowEditor, self).__init__(target, self.fields)
And needs to be repliaced with an explicit call to
editor.Editor.__init__ .. is that even possible?
So what do you think about using inheritance to build up the fields in
related edtiors? what would be your approach to:
1 - building such fields leveraging inheritance.
2 - __init__(target,self.fields)
3 - .commit(self.fields)
--
You received this message because you are subscribed to the Google Groups "Nagare users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nagare-users+***@googlegroups.com.
To post to this group, send email to nagare-***@googlegroups.com.
Visit this group at http://groups.google.com/group/nagare-users.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Nagare users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nagare-users+***@googlegroups.com.
To post to this group, send email to nagare-***@googlegroups.com.
Visit this group at http://groups.google.com/group/nagare-users.
For more options, visit https://groups.google.com/d/optout.