I always run into confusion with who should know about the other.
for example:
Circle.Draw(&canvas) or Canvas.Draw(&circle)
or Draw(&canvas, &circle)
EmployeeVector.Save(&file) or File.Save(&employee_vector)
or even still
void operator() (Employee e) { Save( e.Serialize();}
for_each(employees.begin(), employees.end(),File)
I think I end up “abstracting” too much where I have all kinds of adapters so nobody knows about anybody.
Depends on who has the expertise.
If the only thing you can draw are circles, then of course you could just put that in
Canvasand be on your way. IfCanvashas a method to draw genericShapes, then it falls on the various subclasses ofShapeto draw themselves. For instance, a circle surely knows how to draw itself on a canvas. I doubt a canvas knows natively how to draw a circle, unless you hardcode the functionality, which kinda kills the whole idea of polymorphism.For the same reasons, a vector would probably know how to save itself to a file, but I doubt a file knows what to do with a vector. But a vector can contain a variety of things, so it should delegate most of the work to its actual elements. So the
for_eachidea is probably the best.