an example of the Singleton Pattern and why it is used

Image for post
Image for post

When to use the Singleton Pattern?

The Singleton Pattern is used when you only want one instance of an object at a time.

An example when this pattern is useful is for an access point to a database 💾. In an app, it is beneficial to have one entry point to the database as opposed to multiple entry points (like what would happen with a regular class with a constructor).

How to isolate components that rely on other services for testing purposes

Image for post
Image for post
By spyro on Pinterest

Testing is a very important part of coding, 📈 Test driven development is a very popular way of testing where you write test code before you actually write any ACTUAL code 😲.

A Test is supposed to ISOLATE one function of one service and make sure it works ✅. However, when this service depends on other services, it can be hard to isolate that one section and verify any error is coming from that service😞.

Here is an example of WHY we NEED to mock

  • Say we want to test service A which will transform a List of strings into a sentence. …

An example for the Factory Design Pattern using a factory for animals

What is the Factory Pattern?

Image for post
Image for post
photo by Lenny Kuhne on unsplash

To understand what the factory pattern is and why it is useful, I will use a simile. Imagine you are a dealership and want to order some cars for your dealership. you have two options…

  1. Contact a different factory for each type of car you want to get (Audi, Ford, Honda, Ferrari etc…) and tell each one how many cars you want them to create.
  2. Contact a single factory but tell them what type of car you want as well as how many you want

The first option is akin to the old way of instantiating objects (i.e. a class for Audi(), Honda(), BMW(), etc…). The second option is the factory pattern, it would be achieved by a call such as this Audi myAudi = CarFactory.getCar(“audi”). …

The best practice for retrying service calls

Retrying is a Best Practice

You know that old saying

“If you fall of the horse, dust yourself off and get back on”

It actually has a lot of application when designing and writing software. Occasionally, there are processes or workflows that will fail. What would you do in these cases? Some programmers will simply say

“Not my fault, I called this service and it failed me so I am just going to give an error message to the user and have THEM restart the workflow”

This is undesirable, even if the service works 99% of the time — when it fails — it will be a bad user experience for YOUR customer or user. …

How to make throttle conscious Service Calls

Image for post
Image for post
photo by Logan Weaver on unsplash

Why Should You Limit Your Application?

You might be looking at this and thinking

“Why should I limit my application’s performance? I want my application to load and perform as fast as possible so I shouldn’t limit my API calls”

Well, you’re right and you’re wrong

You shouldn’t arbitrarily limit your API calls that is true. However, sometimes — for large applications — it may be necessary to limit your API calls to avoid being throttled by the API.

Throttling as defined by Adobe as

a process that is used to control the usage of APIs by consumers during a given period. You can define throttling at the application level and API level. …

The right way to store and read objects as json with Jackson ObjectMapper

Image for post
Image for post

Jackson Object Mapper

Introducing, the black magic that is the objectMapper. This library is the go to, state of the art, hands down #1 place to go for translating Json to a java class and vis-versa.

Here is the link to the library if you want to dive deep in all the things you can do with ObjectMapper.

In this short tutorial, we will show how powerful the ObjectMapper is by serializing to and from a Classroom java object — which itself will contain a List of Person Objects — so there will be a decent level of complication since our Classroom is composed of Persons. …

learn to create parallel async tasks

Image for post
Image for post

Why Do Work In Parallel?

In big 💪, fast 🏃‍♂️, and complicated ⁉️ codebases, there is a substantial amount of processing that needs to be done. Doing all of that processing synchronously (one after another) will increase the time 🕐 the code needs to execute.

A good way to get around this problem is to do some of these processes asynchronously when they do not depend on each other.

Best practice Involves using a Thread Pool and wrapping your tasks in a Runnable (does not return anything) or a Callable (does return something).

In this tutorial, we will see how we can speed up our program by creating a few dummy service calls and running them in parallel to make our code fly like a rocket. …

A guide to reading restaurant (or any) JSON properly

Image for post
Image for post
by LogicBig

ObjectMapper Background

JSON is used in many applications to store and send data, the ability to parse and read this data is very important on your journey to becoming a skilled programmer. Before I knew about ObjectMapper, I would manually search for fields in a JSON by doing.

String myVal = json.substring(json.indexOf(field)+ 1, lengthOfVal)

This is a gross and error prone way to get values from a JSON and when a senior dev on my team saw me doing this they showed me the light 🌤️. (The light being Jackson ObjectMapper)

Learn about the Model View Controller design pattern with a cool example 🐕

Image for post
Image for post
Take your Dev Skills to the next level by using MVC

Background on the MVC Design Pattern📚

Tightly coupled code can be easy to write but is a huge pain in the A** when trying to scale…

  • it is hard to work in parallel with other devs in tightly coupled code since there are lots of inter-dependencies.
  • it can be difficult to test since the responsibilities of different sections of code are not well separated or defined.
  • it makes it harder to change one part of the code without needing to change the rest of the code.

The MVC (Model View Controller) is a commonly used design pattern in Applications that have a UI. …


Matthew MacFarquhar

I am a software engineer working for Amazon living in SF/NYC.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store