SICP Goodness - From Pair to Flatmap (II)

Explore the power of list

Guowei Lv

5 minute read

Do you think Computer Science equals building websites and mobile apps? Are you feeling that you are doing repetitive and not so intelligent work? Are you feeling a bit sick about reading manuals and copy-pasting code and keep poking around until it works all day long? Do you want to understand the soul of Computer Science? If yes, read SICP!!! Part I of this series can be found here.

SICP Goodness - From Pair to Flatmap (I)

Explore the power of list

Guowei Lv

3 minute read

Do you think Computer Science equals building websites and mobile apps? Are you feeling that you are doing repetitive and not so intelligent work? Are you feeling a bit sick about reading manuals and copy-pasting code and keep poking around until it works all day long? Do you want to understand the soul of Computer Science? If yes, read SICP!!! Sequence is an important data structure in any programming language, especially in Lisp.

Singleton Pattern Inside and Out

A Brief Summary on Different Flavors of Singleton Pattern

Guowei Lv

5 minute read

Singleton Pattern is so popular that if you know only one design pattern it will probably be it. But do you know it inside out? There are different flavors of this pattern, let’s examine them one by one. Dummy Singleton This is the simplest implementation of Singleton Pattern. Just use a static final field in the class to store an instance of the class, and make all constructors private. See the example below:

Using Interface for Code Organization

Use Interface to better organize your code

Guowei Lv

2 minute read

Another gem found in the book Thinking In Java. Interface in Java can actually be used as a container for closly related concepts. Using Interface and Enum for Subcategorization This can be best explained using an example. Say we have enums for different types of Foods. But we also want to mark that they are all Food. The code is like: public interface Food { enum Appetizer implements Food { SALAD, SOUP, SPRING_ROLLS; } enum MainCourse implements Food { LASAGNE, BURRITO, PAD_THAI, LENTILS, HUMMOUS, VINDALOO; } enum Dessert implements Food { TIRAMISU, GELATO, BLACK_FOREST_CAKE, FRUIT, CREME_CARAMEL; } enum Coffee implements Food { BLACK_COFFEE, DECAF_COFFEE, ESPRESSO, LATTE, CAPPUCCINO, TEA, HERB_TEA; } } Since all enum classes inherit from the built-in java.

Android Design Pattern - Build a SOLID Image Loader

Develop a image loader guided by design patterns

Guowei Lv

6 minute read

SOLID Principles and Design Patterns play an important role in Android development. Lets take a look at how to design and implement an image loader step by step. This example comes from the book Android Source Code Design Patterns - Analysis and Practice. I also rewrote all the code from Java to Kotlin and made some bug fixes. Step 1: Make it work Requirement: Our first version of image loader will just use in-memory cache to cache images loaded from the Internet, we will ignore cache validation for now.