Python
, has the library pathlib
with the concrete class Path
.
I have a class called Cleanup
, that looks like this:
from pathlib import Path
Cleanup:
def __init__(self, source : Path, destination: Path):
self._source = source
self._destination = destination
The Cleanup
class uses certain methods of the Path
class, for example, suffix
, is_dir()
/is_file
, etc.
I was reading here, and the answers suggested that instead of allowing the object to be aware of the other object, it should be made into an abstract class.
From this link:
I don't like A directly knowing about B. But that's a DIP thing not a POJO thing.
My issue is, Cleanup
knows about Path
, but I can't make Path
an abstract class because I have no control over it.
When you have no control over a class you need to pass as a attribute of another class, how do you make an abstraction?
Path
is the abstraction. You can pass in a sub-class to the constructor ofCleanup
if you want.PurePath
is the abstraction.