Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Encapsulation issue
#5
If you have a master class, you could do it like this:

class Top(object):

    def __init__(self, n):
        self.bottoms = [Bottom(self) for bottom in range(n)]

    def send(self, data):
        for bottom in self.bottoms:
            bottom.receive(data)

class Bottom(object):

    def __init__(self, top):
        self.top = top
        self.data = []

    def receive(self, data):
        self.data.append(data)

    def send(self, data):
        for bottom in self.top.bottoms:
            if bottom != self:
                bottom.receive(data)
This way the Bottom instances can send data to each other through their link to the Top instance. The Top instance can also send data down to the Bottom instances. You could add a send_up method to the Bottom class so Bottoms could send data to the Top.

Without a top you can do cross linking:

class Side(object):

    def __init__(self):
        self.siblings = []
        self.data = []

    def link(self, side):
        self.siblings.append(side)
        side.siblings.append(self)

    def receive(self, data):
        self.data.append(data)

    def send(self, data):
        for sibling in self.siblings:
            sibling.send(data)

sides = []
for side in range(3):
    new_side = Side()
    for other in sides:
        new_side.link(other)
    sides.append(new_side)
Here the Side instances can send data to each other through their cross linkages.

Of course, this is just broadcasting to everything. If your windows have different roles, you could just make an attribute for each role to fine tune the communication.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Encapsulation issue - by iFunKtion - Mar-02-2017, 04:04 PM
RE: Encapsulation issue - by ichabod801 - Mar-02-2017, 11:12 PM
RE: Encapsulation issue - by iFunKtion - Mar-07-2017, 11:30 AM
RE: Encapsulation issue - by merlem - Mar-07-2017, 12:11 PM
RE: Encapsulation issue - by ichabod801 - Mar-07-2017, 10:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Encapsulation codinglearner 2 1,525 Apr-02-2024, 01:26 PM
Last Post: DataScience
  Function encapsulation Oldman45 4 2,360 Jan-22-2021, 11:38 AM
Last Post: Oldman45
  Preserve Encapsulation while Displaying Information QueenSvetlana 13 7,190 Dec-07-2017, 06:13 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020