Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Builder Pattern and Flyweight Pattern?

What is the difference between Builder Pattern and Flyweight Pattern in terms of usage, as both of them deals with large number of objects?

like image 571
user366312 Avatar asked Nov 14 '09 05:11

user366312


People also ask

What is builder pattern?

The builder pattern is a design pattern designed to provide a flexible solution to various object creation problems in object-oriented programming. The intent of the Builder design pattern is to separate the construction of a complex object from its representation. It is one of the Gang of Four design patterns.

What are the differences between builder and prototype pattern?

A Factory Design Pattern is used when the entire object can be easily created and object is not very complex. Whereas Builder Pattern is used when the construction process of a complete object is very complex.

What is the difference between builder design pattern and composite design pattern?

Composite creates Parent - Child relations between your objects while Builder is used to create group of objects of predefined types.

What is the meaning of flyweight pattern?

In computer programming, the flyweight software design pattern refers to an object that minimizes memory usage by sharing some of its data with other similar objects. The flyweight pattern is one of twenty-three well-known GoF design patterns.


1 Answers

The Builder pattern is used to create many objects, whereby the Flyweight pattern is about sharing such a collection of objects.

These two patterns both deal with "composites", i.e. objects that may have several elements, but they don't need to be used together at all. The archetype use case for Flyweight is where a pool of a few dozen characters objects are used over and over in a text editor application (this is the example given in the "GoF" book)

like image 148
mjv Avatar answered Sep 23 '22 16:09

mjv