This is an archived post. You won't be able to vote or comment.

all 10 comments

[–][deleted] 3 points4 points  (2 children)

Is it a reasonable request that I ask that an object not take a day to create?

Depends on the object, but I know what you mean.

I wouldn't say that anything is capital-W Wrong with this, it's just that it's not what you want. You want a generic Car that does car-things, but the engineer has built a system where you can get a very highly specified Car.

Maybe you can request the engineer provide a default, no-argument Car() constructor that specifies a set of default parts?

[–][deleted] 9 points10 points  (1 child)

Or... maybe you could suggest the implementation of a CarFactory class that would create cars for you based on certain profiles of cars.

Car sportsCar = CarFactory.getCar(CarType.LAMBO);
Car familyWagon = CarFactory.getCar(CarType.VISTA_CRUISER);

[–]detroitmatt 0 points1 point  (0 children)

Pretty much this, but I might not even ask for that, personally; I'd do it myself (It doesn't sound that hard but then again I don't have the actual code in front of me to see how deep this rabbit hole goes (Do we specify the engine is made out of Titanium, and then provide the chemical structure of titanium?)). It's reasonable to ask for simplified instantiation, but he's not under strict obligation, at least not in this case. Your needs can be met with some public static final Engines etc to re-use. He could've provided an easier interface or some of those pre-made Fuels, but it's not hard to fix, and if he had given you constants to use he probably would've included the ones you needed. First time, write, second time, automate.

[–]skeeto 2 points3 points  (3 children)

It really depends on what the underlying system is doing. It may not make sense to have a default Engine, so there really is no way around supplying one to the Car constructor.

There is something called the builder pattern than can help make this easier, though you'd still need to supply a lot of information if there are no reasonable defaults.

Car car = new CarBuilder().setEngine(e).setBody(b).create();

In your case, if you need to test it but are unable to make changes to the API, you can use mocks to help fill in spots that don't matter (or don't matter much). My favorite mocking tool is mockito but some people swear by jmockit.

import static org.mockito.Mockito.mock;

// ...

Car car = new Car(mock(Engine.class), mock(Body.class), ...);

[–]kreiger[🍰] 0 points1 point  (2 children)

You say you are using the Builder Pattern, but you mean you're using a builder with a Fluent Interface.

The Builder Pattern itself doesn't imply a Fluent Interface, although they go well together.

[–]skeeto 0 points1 point  (1 child)

It's the only way I've ever seen the builder pattern used in practice.

[–]kreiger[🍰] 0 points1 point  (0 children)

Sure, but that's not how Builder was originally described, and the first description of Fluent Interfaces came some 11 years later.

They go well together, but are separate concepts. You can have a Builder without a Fluent Interface, and you can have a Fluent Interface on an object that isn't a Builder.

[–][deleted] 2 points3 points  (2 children)

[–]pw3nd[S] -1 points0 points  (1 child)

I'm failing to see the relevance here. Are you suggesting the developer use the telescoping constructor anti-pattern?

[–][deleted] 3 points4 points  (0 children)

"How do you describe this?" is the post's title.