oop - OO design in python. Up across and down? -


my question how 2 objects have both been created parent class can talk each other. real use case have pyside gui application 2 widgets sitting on centralwidget need connect signal , slot.

however problem more generic have silly example demonstrate problem.

in particular "asksister" method in son, know parent has daughter , need connect 2 methods. however, hard linking connection, means can't run unittests without creating entire object structure.

is there better way?

would less lame if posted real code here (after simplifying)

class parent(object):     def __init__(self):         self.son = son(self)         self.daughter = daughter(self)         self.son.dohomework()   class son(object):     def __init__(self, parent):         self.parent = parent      def dohomework(self):         print 'the answer {0}'.format(self.asksister())      def asksister(self):         return self.parent.daughter.answer()   class daughter(object):     def __init__(self, parent):         self.parent = parent      def answer(self):         return 42  if __name__ == '__main__':     parent = parent() 

i think difficult answer conclusively generic example such 1 present. point these 2 objects must interact, , layout , communication depends on domain , entities represent. different design strategies may equally valid, 1 fitting better specific case.

if on me, register sister , brother, leaving parent out of communication, again, 1 design. if sister , brother view , model, , parent controller, instead have them both talk controller.

another alternative have son request helpservice, sister registered helpprovider. way, son must know helpservice, , gets sister indirectly.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -