Skip to content
This repository has been archived by the owner on Mar 18, 2018. It is now read-only.

Replace constructor with StepBuilder pattern #12

Open
rafakob opened this issue Apr 16, 2016 · 1 comment
Open

Replace constructor with StepBuilder pattern #12

rafakob opened this issue Apr 16, 2016 · 1 comment

Comments

@rafakob
Copy link

rafakob commented Apr 16, 2016

Consider replacing constructor for required fields with StepBuilderPattern. Constructor has two cons:

  • if you got a lot of extras, you need to keep track their order
  • if you change field position in activity, constructor arguments will also be changed, eg:
@Extra String s;
@Extra int i;
startActivity(new DetailActivityIntentBuilder(myString, myInt).build());

Switch position in code:

@Extra int i;
@Extra String s;
// constructor will be changed to: DetailActivityIntentBuilder(int i, String s). 
// You'd have to switch your parameters. And what if their the same type? You're not gonna get compile error.
startActivity(new DetailActivityIntentBuilder(myString, myInt).build());
@kobakei
Copy link
Owner

kobakei commented Apr 16, 2016

Thank you for your feedback.

The constructor with required params is same as IntentBuilder, which has pros that it raises compiler error if some required params are missing.

On the other hand, as you says, a lot of required params and their order may be confusing for developers.
Dose anyone have good solution?

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

No branches or pull requests

2 participants