A: You can have an external party pass the information from one to the other.
class GetInterestingInfo():
def get_info(self):
self.device.read_data()
self.process_raw_data()
return self.processed_data
class UseInterestingInfo():
def use_info(self, interesting_info):
pass
x = GetInterestingInfo()
y = UseInterestingInfo()
y.use_info(x.get_info()):
B: You could bind an instance of one to the other. This is just a cleaner version of A and is really common for GUI type classes where you want a generic way to make two objects communciate.
class GetInterestingInfo():
def get_info(self):
self.device.read_data()
self.process_raw_data()
return self.processed_data
class UseInterestingInfo():
def bind(self, func):
self.get_info_func = func
def use_info(self):
updated_info = self.get_info_func()
x = GetInterestingInfo()
y = UseInterestingInfo()
y.bind(x.get_info)
C: You could have one of the classes create an instance of the other. Since most things in Python are objects you are already doing this all the the time. If class A knows it is going to use class B, have class A create an instance of class B and keep it as an instance variable (or maybe a class variable depending on your need).
class GetInterestingInfo():
def get_info(self):
self.device.read_data()
self.process_raw_data()
return self.processed_data
class UseInterestingInfo():
def __init__(self):
self.get_info = GetInterestingInfo()
def use_info(self):
updated_info = self.get_info()
x = GetInterestingInfo()
D: Create instance of data class that is shared by the producer and consumer.
E: Use a database. Similar to D, but very generic.
F, G, H:... Lots of ways to solve this problem. The best answer is very dependent upon the relationship. There is no "one size fits all" solution.