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).
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
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…
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”). …
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. …
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. …
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. …
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. …
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)
Tightly coupled code can be easy to write but is a huge pain in the A** when trying to scale…
The MVC (Model View Controller) is a commonly used design pattern in Applications that have a UI. …