Why would you use composition over copying code into a single generator?

Prepare for the Yeoman (YN) Test. Use flashcards and multiple-choice questions, all with hints and explanations, to get ready for your upcoming exam. Enhance your learning experience!

Multiple Choice

Why would you use composition over copying code into a single generator?

Explanation:
Composition in Yeoman is about calling other generators from within your generator. This lets you assemble a project by combining small, focused generators instead of copying code into one big file. You gain reuse of proven functionality, easier maintenance because a fix in a shared generator benefits all projects that compose it, and the ability to mix and match pieces to create a tailored scaffold. For example, you could compose with a frontend generator and a backend API generator so you end up with a consistent structure, dependencies, and configuration without duplicating logic. It supports passing options and prompts, and keeps concerns separated while still delivering a single end-to-end scaffold when run. Avoiding dependency management isn’t the aim; composition relies on integrating other generators. It also doesn’t aim to reduce readability or force a single file; it encourages modular, readable, multi-generator setups.

Composition in Yeoman is about calling other generators from within your generator. This lets you assemble a project by combining small, focused generators instead of copying code into one big file. You gain reuse of proven functionality, easier maintenance because a fix in a shared generator benefits all projects that compose it, and the ability to mix and match pieces to create a tailored scaffold. For example, you could compose with a frontend generator and a backend API generator so you end up with a consistent structure, dependencies, and configuration without duplicating logic. It supports passing options and prompts, and keeps concerns separated while still delivering a single end-to-end scaffold when run. Avoiding dependency management isn’t the aim; composition relies on integrating other generators. It also doesn’t aim to reduce readability or force a single file; it encourages modular, readable, multi-generator setups.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy