Write code once use it many times. Creating smaller pieces of code forces developers to write encapsulated software that…