Lego Blocks

01 May 2018

Creating a Lego Block

A professor once told me, “programming is like creating a bunch of lego pieces and putting them together to create something new.” After three years of programming in languages such as C, C++, Java, and JavaScript, I’ve noticed that the code I’ve written is broken down into small “lego blocks”. Some of these blocks are reusable in multiple different programs, they also could be altered to create new blocks. For example, the input of a function could be different from another, but their structures are somewhat similar. These lego blocks resemble design patterns which are reusable solutions to common problems in software design.

Types of Lego Blocks

Just like the lego house on the right, there a three different types of blocks: structural (the foundation of the house), creational (bushes, trees, and flowers), and behavioral (doors, windows, and garage). Structural patterns identify a simple way to show a relationship between classes or objects. Creational patterns make it easier to create objects that will help the situation. A behavioral pattern is used to make objects and classes easily communicate with each other.

Using the Lego Blocks

The underscore library provides programmers with functions that they can reuse over and over in multiple programs. These are blocks have similar structures, but can produce different outcomes based on the function passed to the underscore function. One of functions that I have used many times is the “map” function. This function is an example of a behavioral pattern and specifically, an iterator. This function produces a new array by accessing the elements of a collection and transforming each element based on the function that is passed.

The map function came in handy when creating my team’s final project for our Software Engineering 1 course. For our final project, I used map to accessing each recipe in the recipe collection and print out the ingredients, steps, and dietary restrictions for each recipe.