Let's say I have an Object Structure like this that I import data into from a source:
Reporting: Body: ReportingEntity: DocSpec Reports: ConstEntities DocSpec AdditionalInfo DocSpec MessageSpec
Whenever I import the data I have to check for changes in any of the objects and update the DocSpec objects within dependent of the type of change (
removed data). Then I have to split the object and filter the
removed data into one object and filter
added data into a second object. Each of them will be written to its own XML file and sent to an authority.
On first glance this looks like a great opportunity to use the Visitor Pattern for
FilterReportingVisitor but I also see a major difference here: A visitor only traverses one object structure and does its operations on it. It doesn't work on a second object simultaneously. An
accept() method for
UpdateReportingVisitor would look like this:
class Body(object): def accept(self, visitor, other): """rough draft to communicate the concept. This is not the actual implementation!""" visitor.visit_body(self, other) for self_report, other_report in zip(self.reports, other.reports): self_report.accept(visitor, other_report) for self_info, other_info in zip(self.additional_infos, other.additional_infos): self_info.accept(visitor, other_info)
FilterReportingVisitor wouldn't need that extra argument.
I'm a bit uncomfortable with this solution because of that
other argument in each
accept() method that clearly doesn't belong to the pattern. Would this approach still be considered a visitor pattern? (If no: Does it have a different name?) is there a different (better?) pattern to solve the problem i have?