Skip to content

Refactor downcast of message types in higher level components #94

@TVolden

Description

@TVolden

As I mentioned in #93, we downcast to check. This creates direct dependencies from higher level entities to lower level entities.

Here is an example where we downcast to check if it's an instance of a 3rd part library, thereby creating a hard dependency to that 3rd part library. In this case an XML component, and since XML is being replaced by json in the OCPP standard, this dependency is unfortunate:

                if (payload instanceof Document) {
                    logger.trace("Receive a message: {}", SugarUtil.docToString((Document) payload));
                } else {
                    logger.trace("Receive a message: {}", message);
                }

I have written a short guide to Visitor pattern, that may be a good solution for this issue:
https://github.com/ChargeTimeEU/Java-OCA-OCPP/wiki/Example-of-visitor-pattern-(In-C%23,-oh-my)

Any ideas and/or better approaches?

Is anyone of for a challenge?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions