The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

sest (15) [Avatar] Offline
Hello readers,
We're looking to improve the code examples in Unit Testing in Java before it is sent off to production. If there are any code examples you'd like executable copies of, any topics you'd like an additional example to illustrate, or any examples that would benefit from more depth or detail, let us know!
pianoboy (6) [Avatar] Offline
Re: Improving the examples Chapter 3 Listing 3.3
The example is confusing as there is insufficient information to indicate that a Car can accept a constructor of engine type. The fact that the Car class itself makes the engine private and instantiates a new engine would indicate that the creator of the class did not envisage the ability to swap engines.

Consequently to extend the engine class makes no sense. Why not just extend the Car class itself and add an engine accessor method?
What if the car class also used Brake, SteeringWheel, and Transmission classes privately. Would it make sense to then extend these classes as well and thereby have a ballooning of complexity?
It would be simpler to just extend the car class and provide whatever additional accessors are required.