Skip to content
Sharp

Software Architecture · interview question

Which of the following code snippets demonstrates a proper use of method chaining in a Builder pattern?

Multiple choiceMediumchapter-13-curatedpremiumsoftware-architecturebuilder-pattern
Choose one answer
Answer and explanation

Correct answer

B. OrderBuilder.addItem(item).setAddress(address).isGift().build();

Why

Method chaining in a Builder pattern typically involves calling methods on the builder object itself, leading to a final 'build()' method that creates the desired object. This ensures a fluent and readable API.

Test yourself on Software Architecture

A free test with instant, explained results. No account needed.

Start free test
All Software Architecture questions →