Design Pattern

Design Pattern

A design pattern is a general reusable solution to a commonly occurring problem in software design.

How to Implement an Abstract Factory Design Pattern

In today’s video, I am going to walk through how to implement an Abstract Factory design pattern.

Abstract Factory is a creational design pattern. The main intent of the pattern is to allow abstraction over other factory classes.

  • 00:08 - Explaining what is Abstract Factory Design Pattern
  • 00:45 - Recap of the solution used last week for Factory method design pattern
  • 01:10 - Recap of the problem that we used last week, which we will expand for the Abstract Factory design pattern.
  • 03:06 - Start of the implementation for the Abstract Factory design pattern.
  • 06:05 - New interface/class combination for the Abstract Factory design pattern.
  • 08:10 - Update the Web API controller to use the Abstract Factory class.
  • 09:45 - Update dependency injection container to add the interface and class for the Abstract Factory design pattern.
  • 10:17 - Run and show the demo of the implementation
  • 11:00 - Implement the Abstract Factory design pattern using delegate functions.

#design-pattern #csharp #dotnet

How to Implement an Abstract Factory Design Pattern

Factory Method Design Pattern [An Introduction for .NET Developers (using C#)]

In this video, I am going to walk through the implementation of Factory Method Design Pattern [An Introduction for .NET Developers (using C#)].

I am going to go through a couple of ways we can implement the Factory Method design pattern.

  • 00:05 - Definition of the Factory Method Design pattern
  • 00:32 - Scenario where Factory method design pattern can be used
  • 01:35 - Controller for supporting
  • 01:50 - A non-elegant way of implementing the requirement of the Factory method, without using Factory method design pattern
  • 03:00 - A standard factory class implementation of the Factory method design pattern
  • 05:45 - Trying out the implementation using Swagger
  • 06:40 - Explaining unit testing with Factory method implementation
  • 07:06 - Implementation of the Factory Method Design pattern using a Func delegate
  • 09:08 - Trying out the delegate implementation using Swagger
  • 09:30 - Debugging through the implementation

#dotnet #design-pattern #csharp

Factory Method Design Pattern [An Introduction for .NET Developers (using C#)]
Anil  Sakhiya

Anil Sakhiya


Tips For System Design Interview

You need to know that System Design Interviews are not like Coding Interviews where there are one or two definite solutions for the given problem - instead System Design Interviews are the subjective ones and there can be so many solutions for a particular problem depending on how you approach the problem, how you’ll apply your knowledge to actually build a system, etc. And this is why cracking System Design interviews is not an easy-to-go task.

But, to make things a bit easier for you, here we have an expert Yogita Sharma with us who is currently working as an SDE II at Careem (Uber) - she will tell you some most worthwhile and effective tips that will surely help you to ace in your upcoming System Design Interviews.

  • 00:00 Let’s Start
  • 01:10 Try to Follow an Organized Approach
  • 03:06 Mention the Advantages & Disadvantages of Your Approach
  • 04:36 Don’t Use Complicated Terms/Jargons That You Don’t Know
  • 05:08 Share the Extended Features
  • 05:30 Discuss the Different Properties of the System
  • 05:48 Closing Notes

#developer #interview-questions #design-pattern

Tips For System Design Interview
Dylan  Iqbal

Dylan Iqbal


Domain Driven Design Patterns in Python

Domain-Driven Design (DDD) is an approach to software development that emphasises high-fidelity modelling of the problem domain, and which uses a software implementation of the domain model as a foundation for system design. This approach helps organize and minimize the essential complexity of your software. DDD has been used with success within the traditional enterprise programming ecosystems of Java and .NET, but has seen only limited adoption in the Python community.

In this talk we introduce Python programmers to the core tactical patterns of DDD and show how they can be realised in idiomatic Python, freeing the most valuable parts of your system – the domain model – from onerous dependencies on particular databases or application frameworks.

In this talk we share what we’ve learned from applying DDD in Python to large projects.

#python #design-pattern

Domain Driven Design Patterns in Python
Thomas  Granger

Thomas Granger


Break Singleton Design pattern in Java | Singleton Design Pattern (Live Demo)

Ways to break Singleton Design pattern in Java with Live Demo

Promotional Links
Coupon Code: CODE10
Registration link:

Reflection: Reflection can be caused to destroy singleton property of singleton class

After running this class, you will see that hashCodes are different that means, 2 objects of same class are created and singleton pattern has been destroyed.

Serialization:- Serialization can also cause breakage of singleton property of singleton classes. Serialization is used to convert an object of byte stream and save in a file or send over a network. Suppose you serialize an object of a singleton class. Then if you de-serialize that object it will create a new instance and hence break the singleton pattern.

As you can see, hashCode of both instances is different, hence there are 2 objects of a singleton class. Thus, the class is no more singleton.

Above both hashcodes are same hence no other instance is created.

Cloning: Cloning is a concept to create duplicate objects. Using clone we can create copy of object. Suppose, we create clone of a singleton object, then it wil create a copy that is there are two instances of a singleton class, hence the class is no more singleton.

Two different hashCode means there are 2 different objects of singleton class.
Code Decode Playlists

Most Asked Core Java Interview Questions and Answers :

Advance Java Interview Questions and Answers :

Java 8 Interview Questions and Answers :

Hibernate Interview Questions and Answers :

Spring Boot Interview Questions and Answers :

Angular Playlist :


Subscriber and Follow Code Decode

Subscriber Code Decode :

Linkedin :

Instagram :
#codedecode #breaksingletondesignpattern #javainterviewquestionanswers

#java #design-pattern

Break Singleton Design pattern in Java | Singleton Design Pattern (Live Demo)
Dylan  Iqbal

Dylan Iqbal


Design Patterns in TypeScript

Watch this video to learn five essential Design Patterns, from the ‘Gang of Four’ book, in TypeScript!

#typescript #design-pattern

Design Patterns in TypeScript
Sarai  Thompson

Sarai Thompson


Top 5 Distributed System Design Patterns

Distributed applications are a staple of the modern software development industry. They’re pivotal to cloud storage services and allow web applications of massive scale to stay reactive. As programmers build these systems, they need fundamental building blocks they can use as a starting point and to communicate in a shared vocabulary.

This is where distributed system design patterns become invaluable. While sometimes overused, design patterns are a key skill recruiters are looking for and are essential to stand out in advanced system design interviews.

Today, we’ll explore 5 of the top distributed system design patterns to help you learn their advantages, disadvantages, and when to use them.

Here’s what we’ll cover today:


Top 5 Distributed System Design Patterns

Template Method Design Pattern in Python

The software engineering process often reveals to us many redundant elements inside the structure and code of our software. Knowing this, some of the primary responsibilities of a developer are to write easily understandable and maintanable code - not just solutions.

However, projects often get more complex with time, making the initial software structure a critical element that must be well thought-out and implemented from the very beginning.

Design Patterns are intended to solve this issue.

Design patterns are a set of standards used to optimize specific tasks related to the Object Oriented Programming (OOP) paradigm. They aim to reduce overall count of code lines, optimize structures, and standardize the software architecture.

The Object-Oriented Programming paradigm delivers a structure based on classes, where each class represents a blueprint for an object (instance of that class) that has its own attributes and methods. These classes are related and have their own dependencies, compositions, inheritance, etc. Translating real-life problems and structures to software solutions is the primary motivation for implementing this structure.

In this guide, we’ll explore one of the Behavioral Design Patterns and its implementation in Python: the Template Method.

This design pattern will give us a general method composed of multiple steps. The classes related to our template method class can then call these steps individually or overwrite them.

In addition, we’ll learn how to use the ABC Library in Python, which defines an inheritance relationship for abstract base classes (ABCs). We’ll use this library to create a simple template method example.

#python #design-pattern #oop #programming #developer

Template Method Design Pattern in Python
Alexis Enache

Alexis Enache


Bootstrap 5 Design System

I started to play with this new utility API Bootstrap now has in its latest version. I’ve been using Bootstrap for the last few years, and I don’t want to drop it until I am sure there is a much better alternative.

I must say, I really enjoyed it, and I managed to create a pretty long list of utility classes that could help me write less CSS and make quick changes directly in the HTML. In my opinion, finding the balance between pre-defined components and utility classes is the way to go on long-term.

This is why I started this side-project called, Webpixels CSS. Initially, I built it to help me have a strong foundation for all my websites, but I realized this could help a lot more people who want to implement a nice adaptive design system into their projects.

It includes a comprehensive style guide, new components (besides the ones in Bootstrap), and an entire set of utility classes to extend the default look and feel.

In short, it behaves like a design system. Webpixels CSS is 100% compatible with the latest version of Bootstrap (currently v5), so if you are familiar with it, but you demand something more than it provides, then you should give this tool a try.

#bootstrap #design-pattern #web-development #html #css #sass

Bootstrap 5 Design System

How to Use the BLoC Design Pattern for State Management in Flutter

In this tutorial, you can learn how to use the BLoC design pattern for state management in Flutter and how to implement any feature in BLoC.

Originally published by Pinkesh Darji at

When working on a Flutter app, you might encounter the need to split a large UI component into several smaller ones to improve the readability of the code. With multiple components, it’s crucial to implement effective communication between them. All UI components should be aware of the state of the app at all times. This is called state management.

In Flutter, you can manage the state of your app just by using setState. But while setState can be your best friend, it’s not a good idea to depend on it solely. There are many other factors you should also consider while developing a Flutter app, such as architecture, scalability, readability, complexity, etc. Staying on top of everything requires an effective state management technique.

There are myriad state management solutions available for Flutter, including Provider, InheritedWidget and InheritedModel, Redux, BLoC, GetIt, MobX, Riverpod, etc. In this tutorial, we’ll focus on using the BLoC design pattern for state management in Flutter. We’ll explain what BLoC means and demonstrate how to implement any feature in BLoC.

What is BLoC?

Business logic components (BLoC) allow you to separate the business logic from the UI. Writing code in BLoC makes it easier to write and reuse tests.

In simple terms, BLoC accepts a stream of events, processes the data based on events, and produces the output as states. Take the simple example below:

Process Events and Produces States

As soon as the Rotate 90° button is clicked, the RotateEvent is dispatched to BLoC and the state representing the rotation, i.e. RotatedState, is emitted. The triangle widget rotates itself upon receiving the RotatedState from the BLoC. Similarly, the circle widget changes its color when the Change color to Red button is clicked.

Since the BLoC handles the rotation and changing color operation, both operations can be performed on any widget. This facilitates the reusability of the code.

Important BLoC concepts

Before we dive in, let’s review some basic BLoC concepts and terms so we’re all on the same page.


Events tell BLoC to do something. An event can be fired from anywhere, such as from a UI widget. External events, such as changes in network connectivity, changes in sensor readings, etc., look like this:

class RotateEvent {
  final double angle;

  const RotateEvent(this.angle);

  List<Object> get props => [angle];


BLoC is a man in the middle. All the business logic sits inside the BLoC file. It simply accepts events, performs the logic, and outputs the states. Here’s how it looks:

class TransformationBloc
    extends Bloc<TransformationEvent, TransformationState> {
  TransformationBloc() : super(RotatedState(angle: 0);

  Stream<TransformationState> mapEventToState(
      TransformationEvent event) async* {
    if (event is RotateEvent) {
      yield RotatedState(angle: event.angle);


States represent the information to be processed by any widget. A widget changes itself based on the state.

class RotatedState {
  final double angle;

  const RotatedState({@required this.angle});

  List<Object> get props => [angle];


Cubit is a simpler version of the BLoC pattern. It eliminates the need to write events.

Cubit exposes direct functions, which can result in appropriate states. Writing a Cubit instead of BLoC also reduces boilerplate code, making the code easier to read.

Here’s a simple example:

class TransformCubit extends Cubit<TransformState> {
  TransformCubit() : super(RotatedState(angle: 0));

  void rotate(double angle) {
    emit(RotatedState(angle: angle));


Managing state in Flutter with setState (no BLoC)

Before we highlight the benefits of managing state in Flutter with BLoC, let’s walk through the process of using setState for state management instead.

Our example Flutter app will show a list of available products. A product can be added or removed from the cart by clicking the icon beside the product name. The number of items in the cart is updated accordingly:

Cart Updating

With setState, the entire UI is broken down into three classes:

  1. home.dart is the main file holding the scaffold and AppBar. AppBar contains the cart icon widget
  2. product_list.dart shows the list of products
  3. product_tile.dart shows the individual product item.

Here’s how it looks:

UI Broken Into Three Classes

The list of items in the cart is passed all the way from the Home (top) to the ProductTile (bottom) widget to check whether a given item exits in the cart or not. If it does, the cart icon will be highlighted.

Cart Icon Highlighted

Clicking on the cart icon beside the product name adds the item to the cart. The callback to refresh the cart icon on the AppBar is made from ProductTile (bottom) to Home (top).

Callback to Refresh Cart

**The problem with **setState

The setState approach to state management in Flutter works well for simple apps with just a few components. But for more complex, real-world Flutter apps with deep widget trees, using setState can lead to the following issues:

  • Code duplication — data has to be passed from all widgets to the bottom widget, which makes the code difficult to read
  • Performance degradation due to unnecessary redraws that result from lifting a setState to a parent widget with a deep hierarchy

How to manage state in Flutter with BLoC

Now let’s implement the same feature with BLoC.

First, add the BLoC library:

    sdk: flutter
  cupertino_icons: ^1.0.2
  flutter_bloc: ^7.0.0

Next, create and add a BLoC observer. This helps you determine the sequence of events and states that have occurred, which is great for debugging the app.

void main() { = SimpleBlocObserver();
import 'package:flutter_bloc/flutter_bloc.dart';

/// Custom [BlocObserver] which observes all bloc and cubit instances.
class SimpleBlocObserver extends BlocObserver {
  void onEvent(Bloc bloc, Object event) {
    super.onEvent(bloc, event);

  void onTransition(Bloc bloc, Transition transition) {
    super.onTransition(bloc, transition);

  void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
    super.onError(bloc, error, stackTrace);

Create events to add and remove products from the list of cart items:

import 'package:equatable/equatable.dart';

abstract class CartEvent extends Equatable {
  const CartEvent();

  List<Object> get props => [];

class AddProduct extends CartEvent {
  final int productIndex;
  const AddProduct(this.productIndex);
  List<Object> get props => [productIndex];
  String toString() => 'AddProduct { index: $productIndex }';

Now, create states to represent a product being added and removed:

import 'package:flutter/material.dart';

abstract class CartState {
  final List<int> cartItem;
  const CartState({@required this.cartItem});

  List<Object> get props => [];

class ProductAdded extends CartState {
  final List<int> cartItem;
  const ProductAdded({@required this.cartItem}) : super(cartItem: cartItem);

  List<Object> get props => [cartItem];
  String toString() => 'ProductAdded { todos: $cartItem }';

Write business logic to add and remove products into the cartItems and emit the respective state. The actual list of items in the cart is maintained at the BLoC level.

class CartBloc extends Bloc<CartEvent, CartState> {
  CartBloc() : super(ProductAdded(cartItem: []));

  final List<int> _cartItems = [];
  List<int> get items => _cartItems;

  Stream<CartState> mapEventToState(CartEvent event) async* {
    if (event is AddProduct) {
      yield ProductAdded(cartItem: _cartItems);
    } else if (event is RemoveProduct) {
      yield ProductRemoved(cartItem: _cartItems);

Next, wrap the scaffold widget inside BlocProvider.

BlocProvider is a Flutter widget that makes any BLoC available to the entire widget tree below it. In our case, any widget in between Home (top) and ProductTile (bottom) can have access to the cart, so no need to pass the cart data from the top of the widget tree to the bottom.

    create: (_) => CartBloc(),
    child: Scaffold(
      appBar: CartCounter(),
      body: ProductList(),

Wrap the cart icon and product list inside the BlocBuilderBlocBuilder simply rebuilds the widget inside it upon receiving the new states from the BLoC.

// Cart icon
BlocBuilder<CartBloc, CartState>(builder: (_, cartState) {
  List<int> cartItem = cartState.cartItem;
  return Positioned(
    left: 30,
    child: Container(
      padding: EdgeInsets.all(5),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10),
      child: Text(
        style: TextStyle(fontWeight: FontWeight.bold),
//Product list
 BlocBuilder<CartBloc, CartState>(builder: (_, cartState) {
  List<int> cart = cartState.cartItem;
  return LayoutBuilder(builder: (context, constraints) {
    return GridView.builder(
      itemCount: 100,
      itemBuilder: (context, index) => ProductTile(
        itemNo: index,
        cart: cart,
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: constraints.maxWidth > 700 ? 4 : 1,
        childAspectRatio: 5,

Note: The BlocBuilder for CartBloc is added only in two places because we only want these two widgets to rebuild when something happen at CartBloc. This approach of only refreshing widgets that are required significantly reduces the number of unnecessary redraws.

The next step is to shoot events to CartBloc for adding and removing items in the cart. BlocProvider.of<CartBloc>(context) finds the nearest instance of CartBloc in the widget tree and adds the events to it:

  key: Key('icon_$itemNo'),
  icon: cart.contains(itemNo)
      ? Icon(Icons.shopping_cart)
      : Icon(Icons.shopping_cart_outlined),
  onPressed: () {
        ? BlocProvider.of<CartBloc>(context).add(AddProduct(itemNo))
        : BlocProvider.of<CartBloc>(context).add(RemoveProduct(itemNo));

Now replace BlocBuilder with BlocConsumerBlocConsumer allows us to rebuild the widget and react to the states. It should be only used when you want to rebuild the widget and also perform some action.

For our example, we want to refresh the list and show a snackbar whenever a product is added or removed from the cart:

BlocConsumer<CartBloc, CartState>(
listener: (context, state) { 
      content: Text(
          state is ProductAdded ? 'Added to cart.' : 'Removed from cart.'),
      duration: Duration(seconds: 1),
builder: (_, cartState) {
  List<int> cart = cartState.cartItem;
  return LayoutBuilder(builder: (context, constraints) {
    return GridView.builder();

Optionally, if you want to reduce some boilerplate code and the sequence of the states doesn’t matter to you, try Cubit. Here is what CartCubit would look like:

class CartCubit extends Cubit<CartState> {
  CartCubit() : super(ProductAdded(cartItem: []));

  final List<int> _cartItems = [];
  List<int> get items => _cartItems;

  void add(int productIndex) {
    emit (ProductAdded(cartItem: _cartItems));

  void remove(int productIndex) {
    emit (ProductRemoved(cartItem: _cartItems));

Note: Replace CartBloc with CartCubit throughout the code and fire the events as shown below:

onPressed: () {
      ? BlocProvider.of<CartCubit>(context).add(itemNo)
      : BlocProvider.of<CartCubit>(context).remove(itemNo);

The output is the same but with improved state management:

Cart Updating


Having a solid BLoC architecture in place leads to a good separation of concerns. Although using the BLoC pattern requires more code than using setState, it makes the code more readable, scalable, and testable.

In this tutorial, we covered the basics of using the BLoC pattern in Flutter and walked through a practical example to highlight the benefits of using BLoC for state management in Flutter over the setState approach.

You can find the complete source code for this example on GitHub.

#flutter #mobile-apps #web-development #design-pattern

How to Use the BLoC Design Pattern for State Management in Flutter
Recoding IO

Recoding IO


Create Basic Glassmorphism using Basic HTML & CSS

In this video we gonna learn about basic building block of Glassmorphism.

#css3 #css #user-experience #design-pattern

Create Basic Glassmorphism using Basic HTML & CSS
Poppy Cooke

Poppy Cooke


Builder Design Pattern Explained (with Code Examples)

In today’s video I’ll be taking you through the Builder Pattern in programming, which is one of the most popular and powerful design patterns out there.

The builder pattern allows you to have a more structured way of building instances of your objects, and has many benefits including:

  • immutability
  • easy validation of complex business logic
  • avoids long and confusing constructor parameter lists

Source code for this video:

#design-pattern #developer

Builder Design Pattern Explained (with Code Examples)
Basil  Rasool

Basil Rasool


BAD at Colors? Try ANALOGOUS Color Schemes!

Today, we’re going to step into the world of UI design and focus on how we can easily pick great looking color schemes. This involves using “analogous” color schemes, which are hues that fall next to each other on the color spectrum. I will also show you how you can add tint, shade and tone when working with them.


#ui #ux #design-pattern

BAD at Colors? Try ANALOGOUS Color Schemes!

mehdi hadeli


Awesome .Net Core Education: A curated list of resources for learning .Net Core
A curated list of awesome articles and resources for learning and practicing about .Net Core and its related technologies.

#csharp #dotnet #aspdotnet #testing #design-pattern #api

Awesome .Net Core Education: A curated list of resources for learning .Net Core

mehdi hadeli


Awesome Software Architecture: A curated list of resources about software architecture
A curated list of awesome articles and resources to learn and practice about software architecture, patterns, and principles.

#design-pattern #csharp #dotnet #java #api #python

Awesome Software Architecture: A curated list of resources about software architecture