Introduction

When ClauseGuard processes an uploaded contract, two problems appear immediately at scale. First, it needs to pick the right document parser -- PDF or DOCX -- without hardcoding that decision into business logic. Second, it needs to stamp out hundreds of clause objects fast without reconstructing them from scratch each time.

Prototype and Factory Method are two classic Gang-of-Four creational patterns that address exactly these two problems. This post walks through both: the concept, the UML, the Java code, and when to reach for each one.

What you will learn

● What the Prototype pattern is and when it helps