So I'm coding a way to send events to multiple clients, and then having the clients decide how they want to handle it. I'll exclude the bits that don't lend themselves to explaining the situation.
class Event_Beacon def add_event_eater( self, ee ): self.event_eaters.add( ee ) def broadcast_event( self, e ): for e in self.event_eaters: e.receive_event( e )
Now, with the above, I can create an instance of an Event_Beacon and pass it around. I'm thinking I should stop future me from possibly abusing all that access to the Event_Beacon.
For example, say, I have an Event_Maker. It makes sense for this Event_Maker to have access to the broadcast_event method, but not really add_event_eater. If I just passed it the event beacon instance, I could on some future extension of this particular event maker, haphazardly hack in an add_event_eater inside the event maker.
So, is it good practice to create a limiting interface so that I only give another object exactly what it needs and nothing more? Something like:
class Event_Beacon_Broadcast_Remote def __init__( self, event_beacon ): self.beacon = event_beacon def broadcast_event( self, e ): self.beacon.broadcast_event( e ) # note the lack of add_event_eater in this interface