Let’s understand it by understanding the assembling of computer. When you buy computer (in India), you have two choices,
- Buy the entire computer from a manufacturer (like HP or Dell), the way we buy laptops, or,
- Get it assembled.
For this post, we are only interested in the second option.
When you are assembling your PC, you have an option of selecting which Mother board will you use (Intel / AMD etc.), you can choose the CD/DVD drive (Samsung , Asus, Sony, LG), you can choose which Hard disk you will use (Sony, Asus, Segate etc.), you can choose which company’s (and of what size) RAM will you use, and so on..
This way we are assembling our computer. Final product is the computer which consists of small objects (RAM, Hard disk motherboard, DVD drive etc).
Similarly in Software, an object of a big class (say College) will hold objects of smaller classes (say Library, Lab, etc).. while constructing the object of the bigger class, you have to construct the objects of smaller class also. This process of building the object of a bigger class is a very good case for applying the Builder Design Pattern
Continue reading »