This project demonstrates the Builder Design Pattern through a text conversion system implemented in both C++ and Java. The system processes RTF-like input and converts it into different output formats.
The Builder Pattern is used to construct complex objects step by step. In this implementation:
TextConverterserves as the abstract builder- Concrete builders (
ASCIIConverter,TeXConverter,TextWidgetConverter) create specific representations RTFReaderacts as the director that constructs the object using the builder interface
Just like building a robot piece by piece, our text converter builds the final output format step by step!
- Converts RTF-like text to multiple formats:
- ASCII (plain text)
- TeX (with formatting commands)
- Text Widget (custom format)
- Supports text styling:
- Bold
- Italic
- Underline
- Handles paragraph breaks
- Implemented in both C++ and Java
├── Python/
│ └── app.py
├── C++/
│ └── main.cpp
└── Java/
├── Main.java
└── rtf/
├── ASCIIConverter.java
├── FontStyle.java
├── RTFReader.java
├── TeXConverter.java
├── TextConverter.java
└── TextWidgetConverter.java
Python Implementation Source
- Single file script for simplicity
- Uses classes to define
TextConverterand concrete converters - Easy-to-read and maintainable code
C++ Implementation Source
- Single file modular design with smart pointers
- Implements
TextConverter,RTFReader, and concrete converters - Memory-safe RAII approach
Java Implementation Source
- Multi-file OOP design with
rtfpackage structure - Uses
StringBuilderfor string operations - Interfaces for
TextConverterwith three concrete implementations
- Navigate to the
Pythondirectory. - Run the script using Python, e.g.,
python app.py.
- Navigate to the
C++directory. - Compile the code using a C++ compiler, e.g.,
g++ main.cpp -o TextConverter. - Run the executable, e.g.,
./TextConverter.
- Navigate to the
Javadirectory. - Compile the code using
javac, e.g.,javac Main.java. - Run the program, e.g.,
java Main.
- Separation of Concerns: Construction logic is separated from representation.
- Fine-grained Control: Step-by-step construction of text formatting.
- Multiple Representations: Same construction process creates different text formats.
- Single Responsibility: Each converter handles one specific format.
This project is licensed under the MIT License - see the LICENSE file for details.

