Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assemble dto using additional rules #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexei1volf
Copy link

Hello. We are using geda-genericdto to make our life a bit easier. And we adjusted it for assembling with rules. We added possibility to skip data flow and to set default value (for dataPipe and for virtualDataPipe). May be it is out of scope, but it may seem interesting for you...

Copy link
Collaborator

@denyspavlov denyspavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I think you got some cool ideas here.
And I am genuinely pleased to see this pull request.

Couple of suggestions I would give on this though.

DataPipeFlowRule is not single purpose class, which means that if you need more rules you need to modify it every time. I would rather have two interfaces RuleSet with single method apply and a Rule with isApplicable and apply:

interface RuleSet {

  void apply(Pipe pipe)

}

interface Rule {

   boolean isApplicable(Pipe pipe);

   void apply(Pipe pipe);

}

Then I would have the following logic in the assembleDto() method:


for (Pipe pipe : pipes) {
   ruleset.apply(pipe);
}

so clean an simple process with no "instanceof" or specific checks.

However that means if we do not have a ruleset at all then nothing would happen. So there should be a default RuleSet impl that does the current logic and allows to "plug in" custom rules:


class DefaultRuleSet {

   private Rule[] rules;

   DefaultRuleSet(Rule[] rules) {
       this.rules = rules;
   }

   void apply(Pipe pipe) {

        for (Rule rule : rules) {
            if (rule.isApplicable(pipe)) {
                 rule.apply(pipe);
                 return; // not sure if it makes sense to quit on first applicable rule but it is an option
            }
        }
        // if we are here then no rule fired, so do default write
       pipe.writeFromEntityToDto(entity, dto, converters, resolveBeanFactory(dtoBeanFactory));

   }

}

This way you can create various rules like SkipRule, DefaultValueOnNullRule, LogSecureDataAccessRule etc.

Above code is just quick and dirty pseudo code, but hope you get the idea.

Let me know if this was helpful.

Regards,
Denys

@alexei1volf
Copy link
Author

Thanks for you suggestion, I got the idea and I like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants