Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Factorize builders #990

Description

@DayS

Right now, there is no way to design an advanced application based on generated builders because there is no common classes between each of them.

I started working on a PR for this. The idea is to have the following structure :

  • Builder
    • IntentBuilder
      • ActivityBuilder
      • ServiceBuilder
    • FragmentBuilder

This may also help to implement #883

Activity

  1. added this to the 3.1 milestone on May 11, 2014
  2. self-assigned this
    on May 11, 2014
  3. WonderCsabo commented on May 11, 2014

    @WonderCsabo
    Member

    Great! What is your solution to avoid referencing generated classes?

  4. DayS commented on May 11, 2014

    @DayS
    ContributorAuthor

    This PR isn't intended to resolved this. The idea is just to have a common class between all generated classes. Also I need this for my current project :)

  5. yDelouis commented on May 11, 2014

    @yDelouis
    Contributor

    I have implemented this too in my fork.
    I was waiting for other PRs to be merged to push a new one. Tell me if you want me to create a PR.

  6. DayS commented on May 11, 2014

    @DayS
    ContributorAuthor

    I just take a look at your fork. We have nearly the same implementation, but you can't handle fragment nor support fragment even if different classes because the project will not compile.
    Constructors with fragment and support fragment have to be generated in each activity's/service's inner-builders according to the availability of these classes in the classpath.

    Also, instead of retaining an instance of itself, the flags and extras methods could be implemented like below. You can then remove getThis method.

    @SuppressWarnings("unchecked")
    public I flags(int flags) {
        intent_.setFlags(flags);
        return (I) this;
    }

    In my implementation I also added this constructor in every abstract builders :

    public IntentBuilder(Context context, Intent intent) {
    ...
    }
    

    It may help in some cases.

    And finally, I think you forgot to handle fragment's builders :) You may also add a common class (Builder) for every builders (fragment, activity, service). It should be an empty class but it could help. Mine looked like this :

    public abstract class FragmentBuilder extends Builder {
        protected Bundle args_;
    
        private FragmentBuilder() {
            args_ = new Bundle();
        }
    }

    If you can take care of these points and make a PR it could be awesome ;) I'll merge it very soon as I need this :D

  7. DayS commented on May 12, 2014

    @DayS
    ContributorAuthor

    Merged

  8. WonderCsabo commented on May 13, 2014

    @WonderCsabo
    Member

    BTW i am curious, what is your use-case which needs this feature?

  9. DayS commented on May 31, 2014

    @DayS
    ContributorAuthor

    I have to build a factory of application. So I use lots of generics and abstract classes :) I was struggling on builders because they haven't any common parent class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions