To give some context, I'm using python. We have the following package structure:
/package_name
/request.py # defines class Request
/response.py # defines class Response
Let also assume that we have a bidirectional dependency at class and module levels:
- The method
Request.runreturns aResponseinstance. Responseneeds aRequestinstance to be__init__ialised.
My naive solution would consist defining the abstract class IRequest and IResponse to be stored in the respective modules. As a result
Requestwill implementIRequestand depend onIResponseResponsewill implementIResponsedepend onIRequest
so the circular dependency at class level is defeated.
However, we still have a bidirectional dependency at module level, which prevents the modules to be imported when using python. The bidirectional module dependency can be solved storing the abstract classes in a third module say interfaces.py, but it sounds a dodgy solution to me.
Question: Am I violating any architectural principle? What are possible solutions?