<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Iyanu Falaye</title>
    <description>The latest articles on DEV Community by Iyanu Falaye (@falay).</description>
    <link>https://dev.to/falay</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1158181%2Fe327990c-f740-4487-903c-260bee48e9b0.png</url>
      <title>DEV Community: Iyanu Falaye</title>
      <link>https://dev.to/falay</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/falay"/>
    <language>en</language>
    <item>
      <title>How I Built a Homelab Cluster from 3 Unused Laptops</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 23:47:03 +0000</pubDate>
      <link>https://dev.to/falay/how-i-built-a-homelab-cluster-from-3-unused-laptops-1o16</link>
      <guid>https://dev.to/falay/how-i-built-a-homelab-cluster-from-3-unused-laptops-1o16</guid>
      <description>&lt;h2&gt;
  
  
  Three laptops and an itch
&lt;/h2&gt;

&lt;p&gt;I had three laptops that nobody was using. All three still booted, and all three were more than capable of running Linux. That was the problem: too good to throw away, too boring to keep as they were.&lt;/p&gt;

&lt;p&gt;At the same time I was teaching myself platform engineering: Kubernetes, Terraform, the AWS side of things. Nearly all my practice had happened on throwaway clusters running inside Docker on one machine. Those are fine for learning commands. They teach you nothing about what happens when a machine disappears.&lt;/p&gt;

&lt;p&gt;So the idea was simple. Put Linux on all three laptops, join them into one real cluster, and then break it on purpose. No cloud bill, no free-tier clock ticking. Three physical machines on a shelf.&lt;/p&gt;

&lt;p&gt;This is how that went, including the parts that did not work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why three, not two
&lt;/h2&gt;

&lt;p&gt;My first plan was two laptops. I had a guide for a K3s cluster with two control-plane nodes, and it came with a catch: two servers cannot form a safe quorum on their own. The guide worked around this by running PostgreSQL in Docker as an external datastore.&lt;/p&gt;

&lt;p&gt;Then laptop number three turned up, and the whole design got simpler. Kubernetes keeps its state in etcd, and etcd needs a majority of its members to agree. Three members can lose one and carry on. Two cannot. With three nodes I could drop PostgreSQL entirely and use K3s's embedded etcd. One less service to babysit, and a failure mode I could actually test.&lt;/p&gt;

&lt;p&gt;The Mac never became part of the cluster. It stayed my personal machine, and its only job was to be the remote control: &lt;code&gt;kubectl&lt;/code&gt; and &lt;code&gt;k9s&lt;/code&gt; pointed at the laptops from the outside. Three Linux servers, one client, nothing installed on the Mac beyond command-line tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  The first surprise: I need cat6 cables
&lt;/h2&gt;

&lt;p&gt;With Ubuntu installed on all three, I ran &lt;code&gt;ip a&lt;/code&gt; on the first laptop to find its address. The output told me two things. The subnet was &lt;code&gt;192.168.1.0/24&lt;/code&gt;, and the machine was on Wi-Fi. The Ethernet port, &lt;code&gt;enp0s31f6&lt;/code&gt;, said &lt;code&gt;NO-CARRIER&lt;/code&gt;: nothing plugged in.&lt;/p&gt;

&lt;p&gt;That mattered more than I expected. etcd is sensitive to network jitter, and a Wi-Fi blip can trigger a leader election or even cost the cluster its quorum. A server that roams between access points is a bad foundation for a control plane.&lt;/p&gt;

&lt;p&gt;So the laptops went on cables. One Cat6 run from each machine into a switch, and one more from the switch into a LAN port on the router. (The WAN port is a different one. Plugging a second cable from the switch back into the router creates a loop, which is a good way to take your whole house offline.) The Mac stayed on Wi-Fi, because it is only the client.&lt;/p&gt;

&lt;p&gt;The next &lt;code&gt;ip -br a&lt;/code&gt; showed the wired port up with an address. It also corrected an assumption: the home network was &lt;code&gt;192.168.0.0/24&lt;/code&gt;, not the &lt;code&gt;192.168.1.x&lt;/code&gt; range my first check had shown. Every address I had been planning around was wrong by one octet. Checking before assuming became a theme.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reaching it from anywhere, and pinning the addresses
&lt;/h2&gt;

&lt;p&gt;A homelab you can only reach from the couch is half a homelab. I had been testing SSH against a private LAN address, and I wanted to understand why that would stop working the moment I left the house. The answer is that &lt;code&gt;192.168.x.x&lt;/code&gt; addresses mean nothing outside your own network.&lt;/p&gt;

&lt;p&gt;Tailscale fixed that in an afternoon. Install it, run &lt;code&gt;sudo tailscale up&lt;/code&gt;, open the login link, and every device you sign in joins a private network with stable &lt;code&gt;100.x.x.x&lt;/code&gt; addresses that work from anywhere. No port forwarding, no exposed SSH. That also turned out to matter for a second reason: home 5G routers typically sit behind carrier-grade NAT, so opening a port to the outside is usually not even possible. I turned off key expiry on each laptop, so a headless machine could never lock me out.&lt;/p&gt;

&lt;p&gt;Then came the addresses. A cluster needs its nodes to stay put, and my router's DHCP pool (&lt;code&gt;.100&lt;/code&gt; to &lt;code&gt;.200&lt;/code&gt;) was free to hand any of them a different address after a lease expired. I logged in to the router, a 5G broadband unit, and went looking for a DHCP reservation. The first page I found looked right and was not: it was a Wi-Fi allow and block list. The actual feature was a tab called &lt;strong&gt;Static IP&lt;/strong&gt;, where you bind a MAC address to an address.&lt;/p&gt;

&lt;p&gt;I reserved &lt;code&gt;192.168.0.21&lt;/code&gt;, &lt;code&gt;.22&lt;/code&gt; and &lt;code&gt;.23&lt;/code&gt;, just outside the pool, then bounced each laptop's wired connection so it would pick up the new address. One small lesson from that step: turning Wi-Fi off over an SSH session that came in over Wi-Fi drops the session. Connect through the interface you are &lt;em&gt;not&lt;/em&gt; about to change.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug that cost me an evening
&lt;/h2&gt;

&lt;p&gt;With the network settled, the K3s install itself is almost anticlimactic. One command on the first laptop starts the cluster with &lt;code&gt;--cluster-init&lt;/code&gt;. One command on each of the other two joins them to it. I ran them, and the second and third laptops promptly crashed.&lt;/p&gt;

&lt;p&gt;The first error in the logs was &lt;code&gt;not authorized&lt;/code&gt;. The join token I had passed was being rejected. Fixing the token produced a different error: &lt;code&gt;etcd disabled&lt;/code&gt;. That one was more interesting, because it meant the first laptop was not running etcd at all. It was running K3s's default single-node database, which cannot accept new servers.&lt;/p&gt;

&lt;p&gt;But I had passed &lt;code&gt;--cluster-init&lt;/code&gt;. So I opened the service file K3s had generated and looked at how the flags had actually been recorded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;' --cluster-init' \
' --token=...' \
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every flag had a space inside the quotes. K3s was being handed &lt;code&gt;" --cluster-init"&lt;/code&gt; instead of &lt;code&gt;"--cluster-init"&lt;/code&gt;, did not recognise it as a flag, and silently ignored it. That one invisible character explained both errors: the flag that enables etcd was ignored, and so was the flag that set my token.&lt;/p&gt;

&lt;p&gt;The most likely culprit was the multi-line command I had copied, whose indentation can carry hidden non-breaking spaces into the shell. The fix was boring and worked immediately: uninstall K3s everywhere, generate a fresh token, and run each install as a &lt;strong&gt;single line&lt;/strong&gt; with the token passed as &lt;code&gt;K3S_TOKEN&lt;/code&gt;. I also checked the service file afterwards, instead of trusting that the command had done what I typed.&lt;/p&gt;

&lt;p&gt;And since I had pasted the old token into a chat while debugging, I replaced it. Treat join tokens as secrets, even on a home LAN.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three nodes, all Ready
&lt;/h2&gt;

&lt;p&gt;After the clean reinstall, the first laptop came up as &lt;code&gt;Ready&lt;/code&gt; with the roles &lt;code&gt;control-plane,etcd&lt;/code&gt;. That role list was the proof I had been after: the flag was finally being read, and etcd was running. I joined the second laptop, waited for it to settle, then the third, one at a time so etcd could add each member cleanly.&lt;/p&gt;

&lt;p&gt;Then I ran &lt;code&gt;kubectl get nodes&lt;/code&gt; and saw three machines, all &lt;code&gt;Ready&lt;/code&gt;, all &lt;code&gt;control-plane,etcd&lt;/code&gt;. [Add: your own moment here. What you were doing, what you saw, how it felt.]&lt;/p&gt;

&lt;p&gt;The real test comes next. Stop K3s on one laptop and the other two should carry on, with the stopped node showing &lt;code&gt;NotReady&lt;/code&gt; after about 40 seconds. Start it again and it rejoins. That is the thing a single-node cluster inside Docker could never show me.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would tell someone starting today
&lt;/h2&gt;

&lt;p&gt;The hardware was never the hard part. Almost every problem was a layer underneath Kubernetes: a cable that was not plugged in, a subnet I had guessed wrong, an address the router was free to reassign, and one stray space in a command. If you are building something similar, these are the lessons I would pass on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use wired Ethernet. etcd wants a steady network, and Wi-Fi is not one.&lt;/li&gt;
&lt;li&gt;Use three nodes, not two. An odd number gives you quorum without extra moving parts.&lt;/li&gt;
&lt;li&gt;Pin the addresses early, either with a router reservation or static IPs outside the DHCP pool.&lt;/li&gt;
&lt;li&gt;Put Tailscale on everything first. It solves remote access and the NAT problem together.&lt;/li&gt;
&lt;li&gt;Paste commands as single lines, then check what was actually recorded instead of trusting what you typed.&lt;/li&gt;
&lt;li&gt;Keep the control machine separate. My Mac runs no cluster software, only &lt;code&gt;kubectl&lt;/code&gt; and &lt;code&gt;k9s&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The lab is a working cluster now.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>linux</category>
      <category>devops</category>
      <category>homelab</category>
    </item>
    <item>
      <title>Design Patterns: Template</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:05:42 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-template-23go</link>
      <guid>https://dev.to/falay/design-patterns-template-23go</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
The Template Method Pattern is a behavioral design pattern that outlines the blueprint of an algorithm in a superclass but lets its subclasses override specific steps of the algorithm without changing its structure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;br&gt;
The motivation behind using the Template Method Pattern is to make code reusable and to provide the ability to customize specific steps of an algorithm by overriding it without changing its structure. It is especially helpful when following a well-defined process that has some steps that are always the same and others that can change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
Consider a car manufacturing firm that needs to automate the manufacturing process for the different vehicles to be manufactured. from the &lt;em&gt;CarManufacturingProcess&lt;/em&gt; class, we see that a blueprint has been set for the different types. &lt;br&gt;
1.&lt;strong&gt;initializeManufacturing&lt;/strong&gt; makes sure all the tools/parts needed to start manufacturing are made available.&lt;br&gt;
2.&lt;strong&gt;startManufacturing&lt;/strong&gt; ensures that the manufacturing process starts by assembling the body, installing engine, testing, painting, and packaging.&lt;br&gt;
3.&lt;strong&gt;completeManufacturing&lt;/strong&gt;: ensures the vehicle is ready for distribution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public abstract class CarManufacturingProcess {

    public final void manufactureCar() {
        initializeManufacturing();
        startManufacturing();
        completeManufacturing();
    }

    private void initializeManufacturing() {
        System.out.println("Preparation for manufacturing.");
    }

    protected abstract void startManufacturing();

    private void completeManufacturing() {
        System.out.println("Car manufacturing completed.");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the Sedan division of the manufacturing company, all that needs to be done is to follow the blueprint, ensuring that due process is adhered to and working with its Sedan properties. Additionally, the SUV division also ensures that the blueprint is followed. This is achieved by extending the CarManufacturingProcess class and customizing the properties specific to each division.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package template;

public class SedanManufacturingProcess extends CarManufacturingProcess {

    @Override
    protected void startManufacturing() {
        System.out.println("Manufacturing Sedan: Assembling body, Installing engine, and Painting.");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package template;

public class SUVManufacturingProcess extends CarManufacturingProcess {

    @Override
    protected void startManufacturing() {
        System.out.println("Manufacturing SUV: Assembling chassis, Installing heavy-duty engine, and Painting with durable paint.");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; CarManufacturingProcess sedanProcess = new SedanManufacturingProcess();
        sedanProcess.manufactureCar();

        System.out.println();

        CarManufacturingProcess suvProcess = new SUVManufacturingProcess();
        suvProcess.manufactureCar();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Promotes code reuse by keeping the invariant parts of an algorithm in one place and letting subclasses change only the parts that vary.&lt;/li&gt;
&lt;li&gt;Superclass maintains control over the high-level algorithm while allowing subclasses to refine its parts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Since the template method in the superclass controls the algorithm, it might be restrictive for some subclasses.&lt;/li&gt;
&lt;li&gt;It can make the design more complicated by introducing a lot of subclasses for various parts of the algorithm.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Usecase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A real-life example of the Template Method Pattern could be a workflow in a manufacturing process where the steps like initialization, start, and completion are fixed, but the actual work done in the start phase can vary based on the product being manufactured.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The Template Method Pattern is instrumental in promoting code reuse and algorithm consistency while allowing the flexibility to change parts of the algorithm. It ensures that the structure of the algorithm remains the same, with only specific steps being subject to changes or extensions via the subclasses.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>design</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Design Patterns: Strategy</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:05:33 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-strategy-5ha</link>
      <guid>https://dev.to/falay/design-patterns-strategy-5ha</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
The Strategy Pattern is a behavioral design pattern that makes it possible to choose an algorithm's implementation at runtime. It defines a family of algorithms, encapsulates them all independently, and establishes interoperability between them. The design lets the algorithm change without relying on the clients using it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In situations where there are multiple ways to execute a particular operation, the Strategy Pattern becomes quite useful to help choose among these based on certain dynamic conditions. It allows defining a family of algorithms and making them interchangeable without altering the client code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt; &lt;br&gt;
Considering an e-commerce store is building a system that can accept multiple modes of payment, the use case remains the same, which is to pay a particular amount. The choice is between two possible modes, as shown in the example:&lt;/p&gt;

&lt;p&gt;1.Pay with a credit card.&lt;br&gt;
2.Pay with cryptocurrency.&lt;br&gt;
Depending on the option selected by the customer, which is the condition, the strategy pattern comes into play to choose between these conditions. So, for the e-commerce store, it can use either card payment or crypto payment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package strategy;

public interface PaymentStrategy {
    void pay(int amount);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CreditCardPayment implements PaymentStrategy {
    private String cardNumber;
    private String name;

    public CreditCardPayment(String cardNumber, String name) {
        this.cardNumber = cardNumber;
        this.name = name;
    }

    @Override
    public void pay(int amount) {
        System.out.println("Paid " + amount + " using the credit card: " + cardNumber);
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CryptoCurrencyPayment implements PaymentStrategy {
    private String walletAddress;

    public CryptoCurrencyPayment(String walletAddress) {
        this.walletAddress = walletAddress;
    }

    @Override
    public void pay(int amount) {
        System.out.println("Paid " + amount + " using cryptocurrency to the wallet: " + walletAddress);
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package strategy;

public class ShoppingCart {
    private PaymentStrategy paymentStrategy;

    public void setPaymentStrategy(PaymentStrategy paymentStrategy) {
        this.paymentStrategy = paymentStrategy;
    }

    public void checkout(int amount) {
        paymentStrategy.pay(amount);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ShoppingCart amazonCart = new ShoppingCart();

        // Customer chooses to pay using credit card
        amazonCart.setPaymentStrategy(new CreditCardPayment("1234-5678-9876-5432", "John Doe"));
        amazonCart.checkout(500);

        // Customer chooses to pay using cryptocurrency
        amazonCart.setPaymentStrategy(new CryptoCurrencyPayment("1A2b3C4d5E6F"));
        amazonCart.checkout(300);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Allows choosing from a family of algorithms dynamically.&lt;/li&gt;
&lt;li&gt;Encapsulates the algorithm details from the client that uses it, making the system more modular and easier to maintain.&lt;/li&gt;
&lt;li&gt;Promotes the reuse of the strategy implementations across different contexts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;This can increase the number of objects in the system.&lt;/li&gt;
&lt;li&gt;The client must be aware of the possible strategies to choose the appropriate one.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Usecase&lt;/strong&gt;&lt;br&gt;
An e-commerce application where the payment method can be chosen at runtime is a typical use case for the Strategy Pattern. The application can offer various payment strategies such as credit card, or cryptocurrency, and the user can choose any of these to make a payment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The Strategy Pattern offers a way to manage algorithm implementations more efficiently, promoting flexibility and maintainability. It allows the easy addition of new strategies and modification of existing ones without affecting the client code, making the system more adaptable to changes.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>design</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Design Patterns: State</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:05:25 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-state-10ao</link>
      <guid>https://dev.to/falay/design-patterns-state-10ao</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
The State Pattern is a behavioral design pattern that allows an object to change its behavior when its internal state changes. Instead of having a monolithic object that manages its behavior through conditional statements, we transition between objects representing different states.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;br&gt;
Consider a scenario where a class has multiple states, and its behavior changes based on the state. Managing this using conditional or switch statements can make the code complex and hard to maintain. The State Pattern aims to overcome this issue by representing each state as a separate class, promoting code organization and flexibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
When developing an application that runs on a vending machine, it is important to ensure the customers get the product that was selected. when a customer selects an product, it goes through various states:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No Selection State&lt;/li&gt;
&lt;li&gt;Has Selection State&lt;/li&gt;
&lt;li&gt;Dispensing State &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;No Selection state&lt;/strong&gt;&lt;br&gt;
In this state, the vending machine is waiting for a customer to select for a product.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Has Selection State&lt;/strong&gt;&lt;br&gt;
In this state, the vending machine has a product selection made by the customer and is ready to dispense the selected product.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dispensing State&lt;/strong&gt;&lt;br&gt;
In this state, the vending machine is actively dispensing the selected product to the customer.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In a typical scenario, this is how the system transitions between states:&lt;/li&gt;
&lt;li&gt;Initially, the vending machine is in the "No Selection" state.&lt;/li&gt;
&lt;li&gt;When a customer selects a product, it transitions to the "Has Selection" state.&lt;/li&gt;
&lt;li&gt;When the customer confirms the purchase, it transitions to the "Dispensing" state.&lt;/li&gt;
&lt;li&gt;After dispensing, it goes back to the "No Selection" state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The method in &lt;em&gt;VendingMachineState&lt;/em&gt; outlines what actions can be carried out on the vending machine, different selection state extends this behavior and modify it to suit their own needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface VendingMachineState {
    void selectProduct();
    void dispenseProduct();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class HasSelectionState implements VendingMachineState {
    @Override
    public void selectProduct() {
        System.out.println("Product already selected.");
    }

    @Override
    public void dispenseProduct() {
        System.out.println("Dispensing the selected product.");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class NoSelectionState implements VendingMachineState {
    @Override
    public void selectProduct() {
        System.out.println("Product selected. Ready to dispense.");
    }

    @Override
    public void dispenseProduct() {
        System.out.println("Please select a product first.");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class DispensingState implements VendingMachineState {
    @Override
    public void selectProduct() {
        System.out.println("Product dispensing is in progress. Please wait.");
    }

    @Override
    public void dispenseProduct() {
        System.out.println("Product dispensing is in progress. Please wait.");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class VendingMachine {
    private VendingMachineState state;

    public VendingMachine() {
            state = new NoSelectionState();
    }

    public void setState(VendingMachineState state) {
        this.state = state;
    }

    public void selectProduct() {
        state.selectProduct();
        setState(new HasSelectionState());
    }

        public void dispenseProduct() {
            state.dispenseProduct();
            if (state instanceof HasSelectionState) {
                setState(new DispensingState());
                setState(new NoSelectionState());
            }
        }

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we run the application, where the customer is attempting to select a product and dispense it and the messages we get based on the state the vending machine is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   VendingMachine vendingMachine = new VendingMachine();
        vendingMachine.dispenseProduct();
        vendingMachine.selectProduct();
        vendingMachine.dispenseProduct();
        vendingMachine.selectProduct();
        vendingMachine.dispenseProduct();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Please select a product first.
Product selected. Ready to dispense.
Dispensing the selected product.
Product selected. Ready to dispense.
Dispensing the selected product.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;:&lt;br&gt;
It simplifies the code by eliminating bulky conditional statements.&lt;br&gt;
Encapsulates state-specific code and hides the specifics from the context.&lt;br&gt;
Makes state transitions explicit and straightforward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;:&lt;br&gt;
Can be overkill for a simple state machine.&lt;br&gt;
The number of subclasses can increase, as each state requires a separate class.&lt;br&gt;
&lt;strong&gt;Usecase&lt;/strong&gt;&lt;br&gt;
The State Pattern is useful in scenarios where an object’s behavior is contingent on its state, and it must change its behavior at runtime depending on that state. It’s commonly used in designing finite-state machines, workflow engines, or game mechanics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The State Pattern offers a robust way to manage object states, allowing for more organized, modular, and expressive code. It encapsulates the state-specific logic within separate classes, promoting a cleaner design. While it might introduce more classes, the benefits of maintainability and flexibility often outweigh the drawbacks.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>design</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Design Patterns: Mediator</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:05:19 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-mediator-92m</link>
      <guid>https://dev.to/falay/design-patterns-mediator-92m</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
The Mediator Pattern is a behavioral design pattern that aims to reduce the connectivity between multiple classes or objects by centralizing external communications. Just like its literal meaning, it is a middleman that acts as a broker for communication between two objects. Instead of classes communicating directly with each other, they interact through a mediator object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;br&gt;
In a system where components are interconnected, altering one part may have an impact on other parts as well. Direct communication between objects leads to a tightly coupled system, making it hard to manage and maintain. This is handled by the Mediator Pattern, which serves as a central controller, promotes object-to-object communication, and increases system adaptability and maintainability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
We are a building chat room application, multiple users can join and start sending messages. A user doesn’t send a message to another user directly but sends it through the chat room which acts as a mediator. The chat room handles the message and forwards it to all other users in the room.&lt;/p&gt;

&lt;p&gt;The ChatRoomMediator is the mediator interface that declares a function that shows messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface ChatRoomMediator {
    void showMessage(User user, String message);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ChatRoom is a concrete mediator class that handles communication between user objects. It coordinates users by adding them to a list managed internally and shows each of these users' messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public class ChatRoom implements ChatRoomMediator {
    private List&amp;lt;User&amp;gt; users;

    public ChatRoom() {
        this.users = new ArrayList&amp;lt;&amp;gt;();
    }

    public void addUser(User user) {
        this.users.add(user);
    }

    @Override
    public void showMessage(User user, String message) {
        for (User u : users) {
            // message should not be received by the user sending it
            if (u != user) {
                u.receive(message);
            }
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The User class communicates with other users through the mediator. Each user has a reference to the mediator to send messages, and they receive messages from the mediator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class User {
    private String name;
    private ChatRoomMediator chatMediator;

    public User(String name, ChatRoomMediator chatMediator) {
        this.name = name;
        this.chatMediator = chatMediator;
    }

    public void send(String message) {
        chatMediator.showMessage(this, message);
    }

    public void receive(String message) {
        System.out.println(name + " received: " + message);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We created a chat room called facebookRoom, created three users Alice, Bob, and Matt, and then added them to Facebook.&lt;br&gt;
they start chatting and this basically shows how the mediator pattern handles the communication between the users by simplifying the process and centralizing external communications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ChatRoom facebookRoom = new ChatRoom();

        User alice = new User("Alice", facebookRoom);
        User bob = new User("Bob", facebookRoom);
        User matt = new User("Matt", facebookRoom);


        facebookRoom.addUser(alice);
        facebookRoom.addUser(bob);
        facebookRoom.addUser(matt);

        alice.send("Hi there!");
        bob.send("Hello, Alice!");
        alice.send("Hey bob, where is Matt?");
        matt.send("I am here");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what each user received while chatting using the mediator pattern.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bob received: Hi there!
Matt received: Hi there!
Alice received: Hello, Alice!
Matt received: Hello, Alice!
Bob received: Hey bob, where is Matt?
Matt received: Hey bob, where is Matt?
Alice received: I am here
Bob received: I am here
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The pattern reduces the dependency between various classes by centralizing external communications.&lt;/li&gt;
&lt;li&gt;It simplifies the system maintenance due to decoupled classes.&lt;/li&gt;
&lt;li&gt;It enhances flexibility in terms of object communications and interactions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A mediator can become complex as it centralizes communication between various components.&lt;/li&gt;
&lt;li&gt;Components become dependent on the mediator, leading to a single point of failure.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Usecase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A real-world use case of the Mediator Pattern is in a chat room application, multiple users can join and start sending messages. A user doesn’t send a message directly to another user but sends it through the chat room (mediator). The chat room handles the message and forwards it to all other users in the room.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Mediator Pattern is essential for managing complex communications within a system. It makes interactions simpler and reduces dependencies between system components, promoting a more maintainable and adaptable system. However, careful consideration is necessary to prevent the mediator from becoming a monolithic entity.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>softwareengineering</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Design Patterns: Iterator</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:05:12 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-iterator-2a67</link>
      <guid>https://dev.to/falay/design-patterns-iterator-2a67</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
The Iterator Pattern is a design pattern that provides a way to iterate through a collection of objects without exposing the underlying representation of the collection. It involves two key components: the Iterator and the Iterable collection. The Iterator provides methods to traverse the collection, and the Iterable collection provides a method to get an Iterator.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;br&gt;
In software development, collections of objects, like lists, trees, sets, and maps, are the commonly used data structures. Direct access to the elements within these collections can lead to issues such as unexpected modifications, exposure of internal structure, and increased coupling between components. The Iterator Pattern helps in managing such complexities by providing a standardized way to iterate these collections sequentially without exposing the internal details. &lt;br&gt;
Using Java as an example, before the introduction of iterators, iteration through a collection was not generic. for lists, we use a loop and it won't work for a map or a tree because it does not store data in sequence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
Imagine we are building a system for a restaurant that helps to show all the food on their menu, we can use an iterator pattern to show this as a list, so let's dig in.&lt;/p&gt;

&lt;p&gt;This interface defines a method &lt;em&gt;createIterator()&lt;/em&gt; that creates an iterator for the menu.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Menu {
    MenuIterator createIterator();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;MenuItem&lt;/em&gt; represents individual menu items (food) with attributes like name, description, and price.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MenuItem {
    String name;
    String description;
    double price;

    public MenuItem(String name, String description, double price) {
        this.name = name;
        this.description = description;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;MenuIterator&lt;/em&gt; declares methods hasNext() to check if there are more items in the menu and next() to retrieve the next item in the menu.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface MenuIterator {
    boolean hasNext();
    MenuItem next();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;BreakfastMenu represents a concrete implementation of the menu interface we created before with a collection of menu items. It has an addItem() method to add menu items to the list during initialization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class BreakfastMenu implements Menu {
    private ArrayList&amp;lt;MenuItem&amp;gt; menuItems = new ArrayList&amp;lt;&amp;gt;();

    public BreakfastMenu() {
        addItem("Pancake", "Pancake with chocolate cream", 2.99);
        addItem("Waffles", "Crispy Golden Waffle", 2.59);
        addItem("Coffee", "Ice cold coffee", 1.99);
    }

    private void addItem(String name, String description, double price) {
        menuItems.add(new MenuItem(name, description, price));
    }

    @Override
    public MenuIterator createIterator() {
        return new BreakfastMenuIterator(menuItems);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implements the MenuIterator interface and serves as an iterator for the breakfast menu. It maintains the current position while iterating through menu items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class BreakfastMenuIterator implements MenuIterator {
    private ArrayList&amp;lt;MenuItem&amp;gt; menuItems;
    private int position = 0;

    public BreakfastMenuIterator(ArrayList&amp;lt;MenuItem&amp;gt; menuItems) {
        this.menuItems = menuItems;
    }

    @Override
    public boolean hasNext() {
        return position &amp;lt; menuItems.size();
    }

    @Override
    public MenuItem next() {
        return menuItems.get(position++);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, BreakfastMenu is created, and a BreakfastMenuIterator is obtained using the createIterator() method. The displayMenu() function would be used to print the menu items as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  BreakfastMenu breakfastMenu = new BreakfastMenu();
        MenuIterator breakfastIterator = breakfastMenu.createIterator();

        System.out.println("Breakfast Menu:");
        displayMenu(breakfastIterator);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Breakfast Menu:
Pancake: Pancake with chocolate cream - $2.99
Waffles: Crispy Golden Waffle - $2.59
Coffee: Ice cold coffee - $1.99
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It encloses the internal structure of how the elements are maintained.&lt;/li&gt;
&lt;li&gt;Generic Interface: Provides a generic interface for traversing different collections.&lt;/li&gt;
&lt;li&gt;Allows for more sophisticated traversal and filtering capabilities.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduces an additional layer of abstraction, which can add overhead.&lt;/li&gt;
&lt;li&gt;It might be unnecessary for simple collections, adding undue complexity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Usecase&lt;/strong&gt;&lt;br&gt;
A real-world use case of the Iterator Pattern is in menu items in a restaurant. Different menus like breakfast, lunch, and dinner can be iterated over without exposing the details of how these menu items are maintained, whether it be in a list, array, or any other collection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The Iterator Pattern is instrumental in providing a clean API to the client for iterating various collections, ensuring that the internal details and representation of the collections are well encapsulated. It promotes the Single Responsibility Principle by separating the traversal logic from the business logic of the collection.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>design</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Design Patterns: Observer</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:05:05 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-observer-47aa</link>
      <guid>https://dev.to/falay/design-patterns-observer-47aa</guid>
      <description>&lt;p&gt;Observer pattern is a behavioral pattern where an object is observed by one or more dependents. the object is known as a subject and the dependents are the observers. It is based on the publish-subscribe pattern. It allows for a subscription mechanism that allows many objects to listen and react to changes in another object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;br&gt;
The need to use observer patterns to ensure that the single responsibility principle is adhered to. It allows objects to be loosely coupled where objects don't need to know their dependents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
In a social media application, we want to notify a user's friends whenever the user updates their profile picture so that friends can view and react to the new profile picture.&lt;br&gt;
ProfileObserver is the Observer interface with a method to update the profile picture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface PictureObserver {
    void updatePicture(String newProfilePicture);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WhatsApp is an interface with methods to add, remove, and notify friends.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface WhatsApp {
    void addFriend(PictureObserver observer);
    void removeFriend(PictureObserver observer);
    void notifyFriends();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;UserWhatsApp is the ConcreteSubject. It maintains a list of friends and notifies them when the profile picture changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class UserWhatsApp implements WhatsApp {
    private final List&amp;lt;PictureObserver&amp;gt; friends = new ArrayList&amp;lt;&amp;gt;();
    private String profilePicture = "default.jpg";

    public void setProfilePicture(String profilePicture) {
        this.profilePicture = profilePicture;
        notifyFriends();
    }

    @Override
    public void addFriend(PictureObserver observer) {
        friends.add(observer);
    }

    @Override
    public void removeFriend(PictureObserver observer) {
        friends.remove(observer);
    }

    @Override
    public void notifyFriends() {
        for(PictureObserver friend : friends) {
            friend.updatePicture(profilePicture);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WhatsAppFriend Represents a friend who observes changes in the user profile. When notified of a change, it prints a message indicating that the friend has noticed the new profile picture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class WhatsAppFriend implements PictureObserver{
    private final String name;

    public WhatsAppFriend(String name) {
        this.name = name;
    }

    @Override
    public void updatePicture(String newProfilePicture) {
        System.out.println(name + " noticed that the profile picture has been updated to " + newProfilePicture);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We created a UserWhatsApp and two Friend observers then we added the friends as observers to the UserWhatsApp.&lt;br&gt;
when the user updates the profile picture, the friends will be notified and a message will be printed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UserWhatsApp user = new UserWhatsApp();
        WhatsAppFriend john = new WhatsAppFriend("John");
        WhatsAppFriend cathy = new WhatsAppFriend("Cathy");

        user.addFriend(john);
        user.addFriend(cathy);
        user.setProfilePicture("new_picture.jpg");

        user.removeFriend(john);
        WhatsAppFriend peter = new WhatsAppFriend("Peter");
        user.addFriend(peter);

        user.setProfilePicture("new_picture2.jpg");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The user added John and Cathy and they were notified when the user changed the profile picture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;John noticed that the profile picture has been updated to new_picture.jpg
Cathy noticed that the profile picture has been updated to new_picture.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the user removed john as his friend and added peter then updated his profile picture. only Cathy and Peter are going to be notified of the profile picture change this time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cathy noticed that the profile picture has been updated to new_picture2.jpg
Peter noticed that the profile picture has been updated to new_picture2.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It supports the principle of loose coupling between objects.&lt;/li&gt;
&lt;li&gt;It allows an efficient way to send data to dependents without any change in the subject and the observers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It can lead to complexity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Use cases&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Live data in Android.&lt;/li&gt;
&lt;li&gt;GUI libraries.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The Observer Pattern is a tool that champions code reusability and abstraction. It is widely used, easy to implement, and highly effective in achieving a separation of concerns in object-oriented software design.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Design Patterns: Chain of Responsibility.</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:04:58 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-chain-of-responsibility-2nih</link>
      <guid>https://dev.to/falay/design-patterns-chain-of-responsibility-2nih</guid>
      <description>&lt;p&gt;The Chain of Responsibility pattern is a behavioral design pattern that allows objects to pass the request along a chain of handlers. When a request is received a handler decides on either to process it or pass it along the chain. the object does not know which handler will process the request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;br&gt;
The pattern is used to reduce the tight coupling between the request object and the handlers that process it. Instead of sending a request directly to a specific object and using conditional statements to determine how the request will be processed, the client sends it to the first handler in the chain, thus decoupling the sender and receiver objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
Considering that you are developing an application that determines the customer support staff that will handle a customer's issue for a company. All issues are first checked by Level1CustomerSupport if the issue is "basic", he attends to the customer else he sends the customer to Level2CustomerSupport. The Level2CustomerSupport then checks the customer's issue if it's "intermediate" so he can attend to it if "complex" he sends it to Level3CustomerSupport.&lt;br&gt;
Level3CustomerSupport resolves complex issues only.&lt;/p&gt;

&lt;p&gt;Instead of having a single class with multiple if and else statements checking on how difficult the issue is, the Chain of Responsibility pattern helps to decouple the issue from the handler who handles such issues and makes it pass through the chain of handlers who decide whether they can resolve the issues.&lt;/p&gt;

&lt;p&gt;The CustomerSupport defines the abstract class for creating a customer support object. the level1, level2, and level3 support will extend from this class. &lt;br&gt;
The &lt;strong&gt;setNextLevel&lt;/strong&gt; function helps handle the hierarchy in the customer support department by setting the level above the current support level.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;resolveIssue&lt;/strong&gt; function is the one that checks if the issue can be resolved by the current support level or if it will be delegated to the next support level.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public abstract class CustomerSupport {
    protected CustomerSupport nextLevel;

    public void setNextLevel(CustomerSupport nextLevel) {
        this.nextLevel = nextLevel;
    }

    public abstract void resolveIssue(String issue);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Level1CustomerSupport extends CustomerSupport{
    @Override
    public void resolveIssue(String issue) {
        if ("basic".equals(issue)) {
            System.out.println("Level 1 CSR resolves the basic issue.");
        } else if (nextLevel != null) {
            nextLevel.resolveIssue(issue);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Level2CustomerSupport extends CustomerSupport{
    @Override
    public void resolveIssue(String issue) {
        if ("intermediate".equals(issue)) {
            System.out.println("Level 2 CSR resolves the intermediate issue.");
        } else if (nextLevel != null) {
            nextLevel.resolveIssue(issue);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Level3CustomerSupport extends CustomerSupport{
    @Override
    public void resolveIssue(String issue) {
        if ("complex".equals(issue)) {
            System.out.println("Level 3 CSR resolves the complex issue.");
        } else {
            System.out.println("This issue cannot be resolved.");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Level1CustomerSupport sets the next level to Level2CustomerSupport and Level2CustomerSupport sets the next level to Level3CustomerSupport which defines the hierarchy. As outlined previously, Level1CustomerSupport resolves all the issues and filters to see what can be resolved.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  CustomerSupport customerSupport1 = new Level1CustomerSupport();
        CustomerSupport customerSupport2 = new Level2CustomerSupport();
        CustomerSupport customerSupport3 = new Level3CustomerSupport();

        customerSupport1.setNextLevel(customerSupport2);
        customerSupport2.setNextLevel(customerSupport3);

        customerSupport1.resolveIssue("basic");
        customerSupport1.resolveIssue("intermediate");
        customerSupport1.resolveIssue("complex");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of the application shows that Level1CustomerSupport resolves the basic issues, Level2CustomerSupport, and Level3CustomerSupport resolves intermediate and complex respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Level 1 CSR resolves the basic issue.
Level 2 CSR resolves the intermediate issue.
Level 3 CSR resolves the complex issue.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It reduces the coupling between the request object and the receiver objects (handlers).&lt;/li&gt;
&lt;li&gt;It allows adding or removing responsibilities dynamically by changing the members or order of the chain.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There's a possibility that a  request is not processed; it might fall off the end of the chain if no object handles it.&lt;/li&gt;
&lt;li&gt;It might make the system a bit more complex to understand and maintain due to the indirect communication between objects.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Usecase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The Chain of Responsibility Pattern is an excellent way to decouple sender and receiver objects, allowing multiple objects to handle the request independently. Care should be taken to manage the chain correctly to ensure that the request is handled appropriately and make sure that the code is easy to comprehend.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>design</category>
      <category>programming</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Design Patterns: Facade</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:04:31 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-facade-1kgk</link>
      <guid>https://dev.to/falay/design-patterns-facade-1kgk</guid>
      <description>&lt;p&gt;A set of complex subsystems can have a higher-level simplified interface thanks to the structural design pattern known as facade.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;br&gt;
Interacting with a set of complex classes which includes keeping track of dependencies, initializing objects, and ensuring methods are called in the right order can be cumbersome, error-prone, and can also lead to tight coupling. Instead of letting clients work with these subsystems directly, creating a higher-level interface on top of the complex systems can help simplify the interaction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
Imagine building a food ordering library where a lot of things happen under the scenes right from the cart manager adding the food to the cart, and removing the food from the cart to the Cost calculator that helps calculate the cost of the food order, as well as the Money manager class that handles payment by debiting the client. The kitchen Manager gets informed about the food order and starts to prepare the dish, after the food has been prepared the Delivery Manager handles the delivery to the client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class FoodOrderService {

    public void orderFood(Food food) {
        CartManager cartManager = new CartManager();
        cartManager.addFoodToCart(food);

        CostCalculator costCalculator = new CostCalculator();
        costCalculator.calculateCost(food);

        MoneyManager moneyManager = new MoneyManager();
        moneyManager.debitMoney(food);

        KitchenManager kitchenManager = new KitchenManager();
        kitchenManager.makeFood(food);

        DeliveryManager deliveryManager = new DeliveryManager();
        deliveryManager.deliverFood(food);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CartManager {
    public void addFoodToCart(Food food) {
        System.out.println("Adding Food to cart");
        System.out.println("Added to cart Food :" + food);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CostCalculator {
    public void calculateCost(Food food) {
        System.out.println("Calculating cost of Food:" + food);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MoneyManager {
    public void debitMoney(Food food){
        System.out.println("Debiting money for Food :" + food );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class KitchenManager {
    public void makeFood(Food food) {
        System.out.println("Preparing the food:" + food);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class DeliveryManager {
    public void deliverFood(Food food) {
        System.out.println("Delivering the food:" + food);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is extremely messy to keep track of these processes as a third party or client trying to make use of the library, that is where the facade pattern comes in, it creates a simplified interface where the client interacts with and all the processes are handled under the scene in the right order. &lt;br&gt;
FoodOrderService class simplifies the whole process of ordering food and exposes the &lt;em&gt;orderFood&lt;/em&gt; method which makes things simpler for the client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; FoodOrderService foodOrderService = new FoodOrderService();
        Food food = new Food("Jollof Rice", 2);
        foodOrderService.orderFood(food);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It simplifies the interface for a client&lt;/li&gt;
&lt;li&gt;Reduces dependencies between the client and subsystems&lt;/li&gt;
&lt;li&gt;Helps with abstraction by hiding the intricate nature of the system. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;br&gt;
It can be monolithic if not designed properly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The Facade Pattern provides a method for hiding a subsystem's intricacies by offering a simplified interface for clients to interact with. It promotes decoupling which helps to make systems easier to manage. While it does its job perfectly when designed properly, it is important for care to be taken to ensure that the facade pattern itself does not become too complex.  &lt;/p&gt;

</description>
      <category>architecture</category>
      <category>design</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Design Patterns: Abstract Factory.</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:04:25 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-abstract-factory-2p46</link>
      <guid>https://dev.to/falay/design-patterns-abstract-factory-2p46</guid>
      <description>&lt;p&gt;A creational pattern that provides an interface to create a family of related objects without specifying their concrete implementation. It comprises of many factory methods one for each object that needs to be created. Mainly used when a system needs to be independent of how its objects are created.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;br&gt;
When a system has multiple families of objects it needs to determine which object will be used at runtime.&lt;br&gt;
Provides abstraction between concrete classes and their client to enforce flexibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
    Imagine a family of furniture;  chairs, tables, wardrobes. There are different variants of furniture; wooden &amp;amp; plastic in this case.&lt;br&gt;
     As we established previously, the abstract factory is also known as a factory of factories because it contains many factory methods. Therefore in case we are going to have factory methods that create a chair, table, and wardrobe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Chair {

    String createChair();
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As shown in the Chair interface the &lt;em&gt;createChair&lt;/em&gt; method is the factory method and similarly, we have the same for tables and wardrobes as &lt;em&gt;createTable&lt;/em&gt; and &lt;em&gt;createWardrobe&lt;/em&gt; respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Table {

    String createTable();
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Wardrobe {

    String createWardrobe();
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We know the users often request for the family of furniture so we have to create a &lt;em&gt;FurnitureFactory&lt;/em&gt; that creates a chair, table, and wardrobe all at once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface FurnitureFactory {

    Chair createChair();

    Table createTable();

    Wardrobe createWardrobe();

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, considering  a user is looking to get a wooden furniture we are going to create concrete classes &lt;em&gt;WoodenChair&lt;/em&gt;, &lt;em&gt;WoodenTable&lt;/em&gt;, and &lt;em&gt;WoodenTable&lt;/em&gt; that implements the the &lt;em&gt;Chair&lt;/em&gt;, &lt;em&gt;Table&lt;/em&gt; and &lt;em&gt;Wardrobe&lt;/em&gt; interfaces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class WoodenChair implements Chair{
    @Override
    public String createChair() {
        return "Wooden Chair";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class WoodenTable implements Table {

    @Override
    public String createTable() {
        return "Wooden Table";
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class WoodenWardrobe implements Wardrobe {
    @Override
    public String createWardrobe() {
        return "Wooden Wardrobe";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;WoodenFurnitureFactory&lt;/em&gt; class creates a the wooden furniture that the user needs by creating the objects in the concrete factory methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class WoodenFurnitureFactory implements FurnitureFactory {
    @Override
    public Chair createChair() {
        return new WoodenChair();
    }

    @Override
    public Table createTable() {
        return new WoodenTable();
    }

    @Override
    public Wardrobe createWardrobe() {
        return new WoodenWardrobe();
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine another customer requests for a plastic furtniture, it is easy to creates plastic furnitures becuase we are depending on interfaces and we have a furniture factory (Abstract factory).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PlasticChair implements Chair {
    @Override
    public String createChair() {
        return "Plastic Chair";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PlasticTable implements Table{
    @Override
    public String createTable() {
        return "Plastic Table";
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PlasticWardrobe implements Wardrobe{
    @Override
    public String createWardrobe() {
        return "Plastic Wardrobe";
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PlasticFurnitureFactory implements FurnitureFactory{

    @Override
    public Chair createChair() {
        return new PlasticChair();
    }

    @Override
    public Table createTable() {
        return new PlasticTable();
    }

    @Override
    public Wardrobe createWardrobe() {
        return new PlasticWardrobe();
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A user can request more variants e.g a metallic furniture and the it would be created in record time using the abstract factory pattern.&lt;br&gt;
Now we run our code;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    FurnitureFactory woodenFactory = new WoodenFurnitureFactory();
        Chair woodenChair = woodenFactory.createChair();
        Table woodenTable = woodenFactory.createTable();
        Wardrobe woodenWardrobe = woodenFactory.createWardrobe();

        System.out.println("Wooden Factory makes " + woodenChair.createChair() + ", " +  woodenTable.createTable() + ", " + woodenWardrobe.createWardrobe());

        FurnitureFactory plasticFactory = new PlasticFurnitureFactory();

        Chair plasticChair = plasticFactory.createChair();
        Table plasticTable = plasticFactory.createTable();
        Wardrobe plasticWardrobe = plasticFactory.createWardrobe();

        System.out.println("Plastic Factory makes " + plasticChair.createChair() + ", " +  plasticTable.createTable() + ", " + plasticWardrobe.createWardrobe());

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Wooden Factory makes Wooden Chair, Wooden Table, Wooden Wardrobe
Plastic Factory makes Plastic Chair, Plastic Table, Plastic Wardrobe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It promotes an approach to code for interface instead of concrete implementation.
2.We can add more variants of the same family of object easily.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduces complexity with multiple interfaces. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Real Life Examples&lt;/strong&gt;&lt;br&gt;
Cross-platform UI Toolkit&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
It provides high level approach to object creation particularlly systems that require family of related objects, enhancing cosistency and decoupling. It promotes open close principle especially in the way the system is based on interfaces. To check the implementation via this &lt;a href="//google.com"&gt;link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>softwareengineering</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Design Patterns: Decorator</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:04:21 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-decorator-308g</link>
      <guid>https://dev.to/falay/design-patterns-decorator-308g</guid>
      <description>&lt;p&gt;Decorator pattern is a structural design pattern. It involves adding new functionality to an existing object without necessarily altering its structure. The Decorators also known as wrappers wrap the existing object and then add or override behaviors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why not inheritance?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;For a couple of reasons, it is a good idea to favor decorator over inheritance depending on what the use case is.&lt;br&gt;
You can add responsibilities to objects dynamically at runtime thanks to decorators without developing a new subclass. While using inheritance for every combination of improvements or alterations,  there is a definition of a new subclass. The system may become more complex to comprehend and manage if this results in an explosion of subclasses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The open/Closed Principle states that software entities should be available for extension but closed for modification. Decorator follows this rule because the system can be expanded with new decorators without changing the present code while In the process of creating inheritance superclasses can be modified in order to make subclasses work as intended.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
Here, we are building a juice shop, where you can drink juice and also get the cost of the juice as shown in the interface there's a drink function and a cost function respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Juice {

     String drink();
     int cost();

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are making an assumption that watermelon is the default juice in this shop. The watermelon juice is the concrete implementation of the juice interface as well as the MangoFlavour, OrangeFlavour, and PineAppleFlavour. Mango, Orange, and Pineapple take the juice object in as a constructor. which makes it easy for us to have mixed juice flavours and for them to wrap another juice object as a decorator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class WatermelonFlavour  implements Juice{

    @Override
    public String drink() {
        return "Watermelon flavour";
    }

    @Override
    public int cost() {
        return 5;
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MangoFlavour implements Juice {
    Juice juice;

    public MangoFlavour(Juice juice) {
        this.juice = juice;
    }


    @Override
    public String drink() {
        return "mango " + juice.drink();
    }

    @Override
    public int cost() {
        return juice.cost() + 2;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class OrangeFlavour implements Juice {
    Juice juice;

    public OrangeFlavour(Juice juice) {
        this.juice = juice;
    }

    @Override
    public String drink() {
        return "orange " + juice.drink() ;
    }

    @Override
    public int cost() {
        return juice.cost() + 7;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PineAppleFlavour implements Juice {
    Juice juice;

    public PineAppleFlavour(Juice juice) {
        this.juice = juice;
    }


    @Override
    public String drink() {
        return "pineapple " + juice.drink();
    }


    @Override
    public int cost() {
        return juice.cost() + 4;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Watermelon juice being the default flavour is initialized first and we can confirm that is the only flavour in the system, when we decide to decorate watermelon with mango we see that the juice contains two flavours and when we decorate it with orange we see that it contains three flavours up until the end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Juice juice = new WatermelonJuice();
        System.out.println("Drinking " + juice.drink() + " that costs $" + juice.cost());

        juice = new MangoFlavour(juice);
        System.out.println("Drinking " + juice.drink() + " that costs $" + juice.cost());

        juice = new OrangeFlavour(juice);
        System.out.println("Drinking " + juice.drink() + " that costs $" + juice.cost());

        juice = new PineAppleFlavour(juice);
        System.out.println("Drinking " + juice.drink() + " that costs $" + juice.cost());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;what this implementation and result shows is that we can provide additional functionality to an object without necessarily modifying the object which is one of the &lt;strong&gt;Solid&lt;/strong&gt; principles;&lt;br&gt;
&lt;strong&gt;An object should be open to extension but closed to modification&lt;/strong&gt;.&lt;br&gt;
The result of the decorating process shows us the flavour and the cost.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Drinking Watermelon flavour that costs $5
Drinking mango Watermelon flavour that costs $7
Drinking orange mango Watermelon flavour that costs $14
Drinking pine apple orange mango Watermelon flavour that costs $18
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can add behaviors to objects dynamically without modifying their structure which promotes flexibility.&lt;/li&gt;
&lt;li&gt;Complies with open/close principle.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The system becomes complex because of the introduction of many classes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Without changing the code of an object, the Decorator Pattern offers an elegant way of enhancing the object's behavior.&lt;br&gt;
It adheres to the single responsibility principle by enforcing a single decorator per behavior and the open-close principle by wrapping an existing object without modifying it. Although it may add complexity, its advantages in terms of flexibility and modularity frequently make it a useful tool in a developer's toolbox.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>design</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Design Patterns: Factory Method</title>
      <dc:creator>Iyanu Falaye</dc:creator>
      <pubDate>Sun, 15 Nov 2026 02:04:02 +0000</pubDate>
      <link>https://dev.to/falay/design-patterns-factory-method-3n5a</link>
      <guid>https://dev.to/falay/design-patterns-factory-method-3n5a</guid>
      <description>&lt;p&gt;Factory Method solves the problem of creating product objects without specifying their concrete classes. we expose a method used to create an object without using a direct constructor. it provides an interface to create an object to a parent class while the subclasses are allowed to implement the objects. These objects are not identical but related, Factory Pattern provides a level of abstraction over the object creation process, allowing for more flexible, maintainable, and testable code. It's especially useful in situations where the exact type of the object may not be known until runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Need for a flexible and extensible way to create an object.&lt;/li&gt;
&lt;li&gt;Decouple the client from the objects it needs to create.&lt;/li&gt;
&lt;li&gt;A class cannot anticipate the exact object it must create.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation&lt;br&gt;
   Our example will be a phone factory that creates phones and distributes phones, Imagine creating an iPhone and distributing it, one would need a factory for this. Looking at the code block below, the iPhone factory creates an &lt;strong&gt;Iphone&lt;/strong&gt; by calling &lt;em&gt;createIphone&lt;/em&gt; and it returns an &lt;strong&gt;Iphone&lt;/strong&gt; and it distributes an &lt;strong&gt;Iphone&lt;/strong&gt; by calling &lt;em&gt;distributeIphones&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Iphone {
    @Override
    public String toString() {
        return "This is an iPhone!";
    }
}

class IphoneFactory {

    public Iphone createIphone() {
        return new Iphone();
    }

    public void distributeIphones() {
        System.out.println("Distributing iPhones");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code looks good and solves our problem but what if we want to create Samsung phones and distribute them then we realize that our code is tightly coupled and is not flexible enough which gives reasons to use the factory method (TODO : adds SOLID principles yarns). The code below provides a loosely coupled implementation where we can add different brands of phones with little or no hassle while maintaining flexibility and testability.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface PhoneFactory {
    Phone createPhone();

    default void distributePhones() {
        System.out.println("Distributing Smart Phones");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class IphoneFactory implements PhoneFactory {
    @Override
    public Phone createPhone() {
        return new IPhoneSmartPhone();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Phone {
    public String getPhonePrice();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class IPhone implements Phone {
    @Override
    public String getPhonePrice() {
        return "iPhone Costs $1000";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have a PhoneFactory interface that provides a method to &lt;em&gt;createPhones&lt;/em&gt; which a concrete class can implement as seen in IphoneFactory, the &lt;em&gt;distributePhones&lt;/em&gt; method is left as a default method because it is assumed that distribution does not change across different brands. The &lt;em&gt;createPhones&lt;/em&gt; returns an &lt;strong&gt;Iphone&lt;/strong&gt; object that also depends on the phone Interface which enforces the rule of Liskov substitution principle. Let’s add a factory for &lt;strong&gt;Samsung&lt;/strong&gt; as we tried to do initially that means we will have a &lt;strong&gt;Samsung&lt;/strong&gt; object that depends on the &lt;strong&gt;Phone&lt;/strong&gt; interface as well as a &lt;strong&gt;SamsungFactory&lt;/strong&gt; that depends on &lt;strong&gt;PhoneFactory&lt;/strong&gt; and implements the factory method &lt;em&gt;createPhones&lt;/em&gt;. This design pattern has made the creation of identical but related objects possible. We could add other brands like pixel and one plus and it would still be as easy because we are depending on abstraction rather than concrete implementation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class SamsungFactory implements PhoneFactory {
    @Override
    public Phone createPhone() {
        return new SamsungSmartPhone();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Samsung implements Phone {
    @Override
    public String getPhonePrice() {
        return "Samsung Costs $900";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class cannot anticipate the exact object it must create.&lt;/li&gt;
&lt;li&gt;Class wants subclasses to specify the object it needs to create&lt;/li&gt;
&lt;li&gt;Class delegates responsibility to sub-classes&lt;/li&gt;
&lt;li&gt;Loose coupling&lt;/li&gt;
&lt;li&gt;testing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Complexity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Real Life Example&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Calendar.&lt;/li&gt;
&lt;li&gt;Numberformat.&lt;/li&gt;
&lt;li&gt;ResourceBundle.&lt;/li&gt;
&lt;li&gt;UI Libraries.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Java and other object-oriented languages, the Factory Pattern is a useful tool for creating loose coupling and flexibility in object production. By addressing the requirement to decouple client code from concrete object classes, the software becomes more maintainable and adaptive. Even while it could add a little more complexity, its benefits in terms of code extensibility and maintainability frequently exceed the disadvantages, especially in complex software systems.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>design</category>
      <category>softwareengineering</category>
    </item>
  </channel>
</rss>
