class

A Java Factory Pattern example

Java Design Patterns FAQ: Can you provide an example of the Factory Pattern in Java?

Sure. In this article we'll look at a small-but-complete example of the Factory Pattern ("Factory Design Pattern") implemented in Java.

This is a page from my book, Functional Programming, Simplified

On Using `def` vs `val` To Define Abstract Members in Scala Traits

When I update the Scala Cookbook, I need to update Recipe 8.2, “How to use abstract and concrete fields in Scala traits.” That recipe is written particularly with an OOP developer in mind, and I didn’t write about handling the same situation from an FP perspective.

A good reason to use sealed traits and classes in Scala

This scala-lang.org documentation page shares a good reason to use “sealed” traits and classes: When you created sealed traits, the compiler can easily tell all of the subtypes of your class or trait, and as just one benefit, you don’t need to add a default, “catch-all” case in your Scala match expressions.

This is a page from my book, Functional Programming, Simplified

How to Write a Scala Class That Can Be Used in a ‘for’ Expression

“You must unlearn what you have learned.”

Yoda, Star Wars

Introduction

As a reminder, the reason for the next several lessons on for expressions is so that you can get to a point where you can understand the following code:

A Java FIFO queue class alvin January 18, 2016 - 6:18pm

In my spare time lately I’ve been writing this Android football game, and for the game I needed a simple FIFO queue. I haven’t used Java much lately, and after a quick Google search showed things that were more complicated than what I had in mind, I wrote my own FIFO queue.