class File: def __init__(self, filename): self.filename = filename def open(self): ... def read(self): ... def write(self): ... def close(self): ... # end of class File class Socket: def __init__(self, address, port): self.address = address self.port = port def open(self): ... def read(self): ... def write(self): ... def close(self): ... # end of class Socket # read_data works equally well with both File and Socket def read_data(source): data = source.read() source.close() return data