Skip to Content
Functional Programming in Java
book

Functional Programming in Java

by Venkat Subramaniam
February 2014
Intermediate to advanced
160 pages
4h 59m
English
Pragmatic Bookshelf
Content preview from Functional Programming in Java

Separating Concerns Using Lambda Expressions

We often create classes to reuse code; we have good intentions, but it’s not always the right choice. By using higher-order functions, we can accomplish the same goals without needing a hierarchy of classes.

Exploring Design Concerns

Let’s start with an example to sum asset values as a way to illustrate the design idea of separation of concerns. We’ll build it in iterations. The design we first create will mix multiple concerns in one method, but we’ll quickly refactor to make the method more cohesive. Let’s start with an Asset class.

designing/fpij/Asset.java
 
public​ ​class​ Asset {
 
public​ ​enum​ AssetType { BOND, STOCK };
 
private​ ​final​ AssetType type;
 
private​ ​final​ ​int​ value; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Functional Programming in Java

Functional Programming in Java

Pierre-Yves Saumont

Publisher Resources

ISBN: 9781941222690Errata Page