Constructor Injection and Null Object Design Patterns

The Constructor Injection design pattern is a pattern that helps you declare all the required dependencies of a class in it's constructor. This is useful because it helps you decouple the code, you can specify an interface instead of a concrete type, remember, program to an interface. Also, in the constructor it is easier to … Continue reading Constructor Injection and Null Object Design Patterns

Composition Root Pattern: How to Write Modular Software

The composition root is a design pattern which helps you structure a software application by implementing a class that builds all the other classes. In this example we will examine this pattern in Python. Here's the object graph of the classes that we're going to implement: I have designed a sample application that we're going … Continue reading Composition Root Pattern: How to Write Modular Software

LeetCode: Arrays 101: Inserting Items Into an Array

Hello, Here are my solutions for the second part of the card: Arrays 101, from LeetCode. Duplicate Zeroes Given an array of integers, remove duplicate zeroes and shift the remaining elements. https://leetcode.com/problems/duplicate-zeros/ class Solution: def duplicateZeros(self, arr: List[int]) -> None: """ Do not return anything, modify arr in-place instead. """ index = 0 arr_length = … Continue reading LeetCode: Arrays 101: Inserting Items Into an Array