How Does Python Implement Dependency Injection Since It Has No Interfaces?
As I understand it, a client (the core program) needs to have a common type to allow a plugin, another object, etc. to be passed successfully to a client. I saw this answer on SO
Solution 1:
The need for an interface is just a detail of Java. It's the thing that lets you define a function that can accept an instance of any of several otherwise-unrelated types.
Since every Python function can accept an instance of any type, there is no need for anything comparable.
Of course, if you pass in an object that doesn't have the required capability then you'll get an exception at some point. Python has what is called "implicit interfaces" -- the interface required by the function is whatever operations it performs on the object in the expectation of them working.
Post a Comment for "How Does Python Implement Dependency Injection Since It Has No Interfaces?"