O'Reilly logo

Scala Functional Programming Patterns by Atul S. Khot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required