---
title: "Short note: generator-based reuse"
subject: "Software Engineering"
chapter: 5
key: "semester_5/software_engineering:generator-based-reuse"
source: https://www.bctengineer.com/q/semester_5/software_engineering/generator-based-reuse
site: BCT Engineering
---

# Short note: generator-based reuse

Software Engineering · Chapter 5: Software Reuse

- Asked in: year not given, 3 marks
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/software_engineering/generator-based-reuse
- Whole chapter: https://www.bctengineer.com/md/semester_5/software_engineering/chapter-5

## Question

Write a short note on generator-based reuse.

## Short answer

Generator-based reuse captures domain knowledge in a program generator; developers write a domain-oriented description and the generator produces code automatically. Examples include yacc/lex, CASE code generators, and GUI builders. It is very productive in narrow, well-understood domains but generated code may be inefficient and the generator itself is expensive to build.

## Answer

**Generator-based reuse** is an approach in which reusable knowledge is captured in a **program generator** instead of in code components. The developer describes *what* is needed in a domain-oriented language or through an interactive tool, and the generator automatically produces the program code.

```text
+-------------+    +-----------+    +-----------+
| Application |--->| Program   |--->| Generated |
| description |    | generator |    | program   |
+-------------+    +-----------+    +-----------+
                         ^                ^
                         |                |
                 +-------------+  +--------------+
                 | Application |  | Extra hand-  |
                 | domain      |  | written code |
                 | knowledge   |  | (if needed)  |
                 +-------------+  +--------------+
```

**Examples**
- **Application generators** for business data processing (report and form generators).
- **Parser and lexical analyser generators** such as yacc and lex, which generate a parser from a grammar.
- **Code generators in CASE tools** that produce code from UML/design models.
- **GUI builders** that generate interface code from drag-and-drop screens.

**Advantages**
- Very cost-effective: a short description produces a lot of correct code.
- Easier for domain experts and end-users than writing code.
- Generated code is consistent and follows standards.

**Disadvantages**
- Applicable only to well-understood, limited domains where abstractions can be clearly mapped to code.
- Generated code may be less efficient and hard to read or modify by hand.
- Building the generator itself is expensive.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is captured in generator-based reuse?
   A. Domain knowledge in a program generator
   B. Code in a component library
   C. Classes in a framework
   D. Test cases
   Answer: A. Reusable knowledge is built into the generator, which produces code from a description. (Key point: Core idea)

2. Which is an example of a generator?
   A. Spring MVC
   B. VxWorks
   C. yacc and lex
   D. Windows
   Answer: C. yacc and lex generate parsers and lexical analysers from grammars. (Key point: Examples)

3. Which is a disadvantage of generators?
   A. Generated code is inconsistent
   B. They work for any domain
   C. They need long hand-written programs
   D. They apply only to well-understood, limited domains
   Answer: D. Generators only work where domain abstractions map clearly to code, and building them is expensive. (Key point: Disadvantage)

## Related in Software Engineering

- [Reuse framework versus program generator](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Aframework-vs-generator) — Software Engineering, chapter 5

## Related in other subjects

- [Microprocessor relaying via generator field current](https://www.bctengineer.com/question.md?key=semester_6%2Fswitchgear_and_protection%3Amicroprocessor-generator-field) — Switchgear and Protection, chapter 8
- [Reactance diagram 1000 kVA base and generator currents](https://www.bctengineer.com/question.md?key=semester_4%2Fpower_system_analysis_i%3Areactance-diagram-1000kva-load-current) — Power System Analysis I, chapter 3
