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

Support Polymorphism #42

Open
simschla opened this issue Jan 7, 2020 · 0 comments
Open

Support Polymorphism #42

simschla opened this issue Jan 7, 2020 · 0 comments

Comments

@simschla
Copy link

simschla commented Jan 7, 2020

I would love to have support for polymorphism in Builderberg.

Simple example:

public abstract class Vehicle {
    private final String make;
    // [...]
}

public class Car extends Vehicle {
    private final int seatingCapacity;
    // [...]
}

public class Truck extends Vehicle {
    private final int payloadCapacity;
    // [...]
}

As a suggestion, this is how resulting builders could look like:

public abstract class Vehicle {
    // [...]

    // protected instead of public?
    // non-final?
    protected static class Builder {
        // [ all fields of type Vehicle ]
    }
}

public class Car extends Vehicle {
    // [...]

    public static final class Builder extends Vehicle.Builder {
        // [ all fields of type Car ]

        // PLUS:
        // Overrides for all methods of Vehicle.Builder (in order to allow strongly-typed fluent usage) - delegating to Vehicle.Builder but casting return value to Car.Builder)
    }
}
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

No branches or pull requests

1 participant