Serving the curry
Duplicated code is a major code smell. We need to apply the extract method refactoring to remove this smell. For more information, refer to https://sourcemaking.com/refactoring/extract-method.
Instead of copying and pasting, we should reuse the code. One example of such code reuse is the template method design pattern. We have a common algorithm shell. This shell has blanks, that is, unspecified behavior. The blanks are filled with a specific behavior as needed. Too formal and pedantic? Let's come back to our real-world example and look at moms and their kids.
In our example, there are moms who have different professions. There are working moms, engineer moms, doctor moms, and teacher moms. All moms love their kids. This is the common part. However, an engineer mom will fix machines, design algorithms, and build houses. On the other hand, a doctor mom will perform surgeries, prescribe medicines to the patients, and take care of newborn babies. A teacher mom will teach children...