Abdelstar Ahmed
Abdelstar Ahmed

Reputation: 122

How to make methods flow like glide library?

Glide.with(context)
.load(param)
.apply(param)
.into(param);

Upvotes: 0

Views: 441

Answers (1)

user9335240
user9335240

Reputation: 1799

It is a design pattern called Builder.

Builder design pattern , sourcemaking.com

Its about returning this

class UserObjectBuilder {
    private int id;
    private String name;
    private String email;

    UserObjectBuilder withId(int id) {
        this.id = id;
        return this;
    }

    UserObjectBuilder withName(String name) {
        this.name = name;
        return this;
    }

    UserObjectBuilder withEmail(String email) {
        this.email = email;
        return this;
    }

    User build() {
        return new User(id, name, email);
    }
}

Upvotes: 3

Related Questions