Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Builder Pattern

This directory contains examples of the Builder design pattern implemented in TypeScript.The Builder pattern separates the construction of a complex object from its representation which allows for different types and representations to be created with the same construction code. Thus the pattern is used when you want to create a complex object step by step. It is particularly useful when an object may have various configurations and optional components, and you want to provide a clear and consistent way to construct the object. There is also the director which defines common products that will be made using a given builder, although not necessary the director comes in handy.If at any point you would like to obtain and run these files refer to the root README.md found here.

Conceptual Example

The conceptual example can be found in conceptual.ts and ran from conceptual.js. The TypeScript files contains the code and explanations of what each element does in the design pattern.

Real-World Example

The real worl example I chose to implement is car production. The TypeScript file is names car_production.ts and the executable JavaScript file, with node, is called car_production.js. This example uses the builder pattern to create cars and car manuals. The Builder interface defines the parts that we want to put in our car/manual. The CarBuilder and CarManualBuilder are responsible for implementing the Builder interface to build Car and CarManual objects respectivly. The parts that we consider are CarType, Seats, Engine, Transmission, TripComputer, and Radio. These parts are built and added to the object via the concrete builder classes. The builders can then be used to get the resulting object, a Car ot CarManual, which can be interacted with to examine the parts put in. In the Director class I defined three functions to create specific cars that may be created often. The three functions create Sports Cars, SUVs and Sedans.