<?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: Abdulfatai Abdulwasiu Aremu</title>
    <description>The latest articles on DEV Community by Abdulfatai Abdulwasiu Aremu (@wastech).</description>
    <link>https://dev.to/wastech</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1146918%2F01c16a76-d24d-4593-b185-bd9c82527da4.png</url>
      <title>DEV Community: Abdulfatai Abdulwasiu Aremu</title>
      <link>https://dev.to/wastech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wastech"/>
    <language>en</language>
    <item>
      <title>System Design Basics 🍕 + Spring Boot</title>
      <dc:creator>Abdulfatai Abdulwasiu Aremu</dc:creator>
      <pubDate>Tue, 23 Sep 2025 22:23:05 +0000</pubDate>
      <link>https://dev.to/wastech/-14j4</link>
      <guid>https://dev.to/wastech/-14j4</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/wastech" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1146918%2F01c16a76-d24d-4593-b185-bd9c82527da4.png" alt="wastech"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/wastech/system-design-basics-spring-boot-2dbo" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;System Design Basics 🍕 + Spring Boot&lt;/h2&gt;
      &lt;h3&gt;Abdulfatai Abdulwasiu Aremu ・ Sep 22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#springboot&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#java&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#systemdesign&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>programming</category>
      <category>springboot</category>
      <category>java</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>System Design Basics 🍕 + Spring Boot</title>
      <dc:creator>Abdulfatai Abdulwasiu Aremu</dc:creator>
      <pubDate>Mon, 22 Sep 2025 22:31:21 +0000</pubDate>
      <link>https://dev.to/wastech/system-design-basics-spring-boot-2dbo</link>
      <guid>https://dev.to/wastech/system-design-basics-spring-boot-2dbo</guid>
      <description>&lt;p&gt;I explained System Design to my friend using a pizza shop 🍕&lt;br&gt;
 Turns out it’s the easiest way to get Scalability, Latency, Throughput, Consistency, and Availability!&lt;/p&gt;

&lt;p&gt;1️ Scalability – More chefs, more pizzas&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@RestController&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PizzaController&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/order"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;orderPizza&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"🍕 Pizza ready!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1 instance = 10 orders/min&lt;br&gt;
 10 instances = 100 orders/min&lt;/p&gt;
&lt;h2&gt;
  
  
  2️ Latency – How long until your pizza arrives?
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/order"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;orderPizza&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;InterruptedException&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 3 sec delay&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"🍕 Pizza ready after wait!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Delays = unhappy customers&lt;/p&gt;
&lt;h2&gt;
  
  
  3️ Throughput – Pizzas per minute
&lt;/h2&gt;

&lt;p&gt;Run a load test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ab &lt;span class="nt"&gt;-n&lt;/span&gt; 1000 &lt;span class="nt"&gt;-c&lt;/span&gt; 50 http://localhost:8080/order
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One endpoint, but throughput depends on kitchen “power.”&lt;/p&gt;

&lt;p&gt;4️ Consistency – Pizza means pizza&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@RestController&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PizzaController&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/order"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;orderPizza&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;random&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s"&gt;"🍝 Pasta?"&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"🍕 Pizza"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Users want the same result every time!&lt;/p&gt;

&lt;h2&gt;
  
  
  5️ Availability – Always open
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/health"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;health&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"✅ I’m alive!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Service stays open, even if one instance crashes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;System design is like running a pizza shop 🍕&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Scalability → more chefs&lt;/li&gt;
&lt;li&gt; Latency → wait time&lt;/li&gt;
&lt;li&gt; Throughput → orders per min&lt;/li&gt;
&lt;li&gt; Consistency → pizza = pizza&lt;/li&gt;
&lt;li&gt; Availability → always open&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What’s your favorite system design analogy?&lt;/p&gt;

</description>
      <category>programming</category>
      <category>springboot</category>
      <category>java</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>⚙️ Mastering Transactions in Java Spring Boot: A Developer's Guide</title>
      <dc:creator>Abdulfatai Abdulwasiu Aremu</dc:creator>
      <pubDate>Fri, 16 May 2025 01:04:04 +0000</pubDate>
      <link>https://dev.to/wastech/mastering-transactions-in-java-spring-boot-a-developers-guide-2dom</link>
      <guid>https://dev.to/wastech/mastering-transactions-in-java-spring-boot-a-developers-guide-2dom</guid>
      <description>&lt;p&gt;Imagine this: you're transferring money from one bank account to another. The amount gets debited from your account, but due to a power outage or system crash, it never reaches the recipient. Now both parties are at a loss.&lt;br&gt;
That's exactly the kind of problem transactions solve. In this guide, we'll dive deep into what transactions are, how Spring Boot makes them easy to implement, and walk through a practical bank transfer example to see them in action.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 Understanding Transactions&lt;/strong&gt;&lt;br&gt;
A transaction in software terms is a sequence of operations performed as a single logical unit of work. The operations must either all succeed or all fail together — no middle ground. This approach ensures the integrity and consistency of data, especially in mission-critical systems like banking, inventory management, or order processing.&lt;/p&gt;

&lt;p&gt;To enforce this, transactions are built around the ACID principles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;*&lt;em&gt;Atomicity *&lt;/em&gt; ensures that either all steps in a transaction happen or none do.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency&lt;/strong&gt; guarantees that the database stays in a valid state before and after the transaction.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Isolation&lt;/strong&gt; keeps transactions from interfering with each other while executing simultaneously.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Durability&lt;/strong&gt; ensures that once a transaction is completed, the changes are permanently saved—even if the system crashes right after.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🚀 Transaction Management in Spring Boot&lt;/strong&gt;&lt;br&gt;
Spring Boot uses a simple and powerful annotation called @Transactional to wrap a method in a transaction. Once you annotate a service method, Spring handles all the behind-the-scenes magic like opening a transaction, committing it if successful, or rolling it back in case of failure.&lt;br&gt;
But how does this work practically? Let’s go through an example step by step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🏦 Building a Bank Transfer Example&lt;/strong&gt;&lt;br&gt;
Let’s assume we’re building a small banking system. A user should be able to transfer money from one account to another. If anything goes wrong during the process, we want the whole transaction to roll back.&lt;/p&gt;

&lt;p&gt;Step 1: Define the Account Entity&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Entity
public class Account {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String owner;
    private Double balance;

    // Getters and setters
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simple JPA entity that represents a bank account with an owner and a balance.&lt;br&gt;
Step 2: Create the Repository&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 AccountRepository extends JpaRepository&amp;lt;Account, Long&amp;gt; {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The repository gives us CRUD access to the Account data.&lt;br&gt;
Step 3: Write the Service Layer with Transactions&lt;br&gt;
&lt;/p&gt;

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

    @Autowired
    private AccountRepository repository;

    @Transactional
    public void transfer(Long fromAccountId, Long toAccountId, Double amount) {
        Account sender = repository.findById(fromAccountId)
                .orElseThrow(() -&amp;gt; new RuntimeException("Sender account not found"));

        Account receiver = repository.findById(toAccountId)
                .orElseThrow(() -&amp;gt; new RuntimeException("Receiver account not found"));

        if (sender.getBalance() &amp;lt; amount) {
            throw new RuntimeException("Insufficient funds");
        }

        sender.setBalance(sender.getBalance() - amount);
        receiver.setBalance(receiver.getBalance() + amount);

        repository.save(sender);
        repository.save(receiver);

        // Simulate an error to trigger rollback
        // throw new RuntimeException("Simulated transfer failure");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s the heart of it: the &lt;strong&gt;@Transactional&lt;/strong&gt; annotation ensures that if any exception occurs during the transfer (even after the first save), Spring will automatically roll back all database changes. This prevents half-completed operations that could lead to corrupted data.&lt;br&gt;
Step 4: Expose the Transfer Endpoint&lt;br&gt;
&lt;/p&gt;

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

    @Autowired
    private BankService bankService;

    @PostMapping("/transfer")
    public ResponseEntity&amp;lt;String&amp;gt; transfer(@RequestParam Long from,
                                           @RequestParam Long to,
                                           @RequestParam Double amount) {
        bankService.transfer(from, to, amount);
        return ResponseEntity.ok("Transfer successful");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a user calls this endpoint, money is transferred from one account to another — and if something fails, it fails safely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔁 What Happens on Failure?&lt;/strong&gt;&lt;br&gt;
If the service method throws a RuntimeException (or an unchecked exception), Spring catches it and triggers a rollback. That means any balance changes, even if saved, are undone before being committed to the database.&lt;br&gt;
If you want to roll back on checked exceptions (like IOException), you’ll need to explicitly specify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Transactional(rollbackFor = IOException.class)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Spring to treat those exceptions as fatal and rollback-worthy too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🛡️ Best Practices for Transactions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always place @Transactional on service layer methods, not controllers or repositories.&lt;/li&gt;
&lt;li&gt;Avoid complex logic inside transactional methods; keep them focused and minimal.&lt;/li&gt;
&lt;li&gt;Be careful with lazy-loaded entities — once the transaction closes, those proxies can’t fetch additional data.&lt;/li&gt;
&lt;li&gt;Use logging or monitoring to track transaction boundaries during debugging.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🎨 Visual Flow: Transaction in Action&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client ➜ /transfer
        ↓
BankController ➜ Calls BankService.transfer()
        ↓
@Transactional boundary starts
        ↓
1. Debit sender
2. Credit receiver
3. Save both accounts
        ↓
Error? ➜ Rollback changes
Success? ➜ Commit transaction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧪 How to Test Transactions&lt;/strong&gt;&lt;br&gt;
Testing transaction rollbacks is just as important as implementing them.&lt;br&gt;
&lt;/p&gt;

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

    @Autowired
    private BankService bankService;

    @Test
    void testTransactionRollback() {
        // Create mock accounts with balances
        // Attempt to transfer with forced exception
        // Assert balances are unchanged
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can simulate a failure during a transfer and ensure balances are reverted. This confirms that transactions are working correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎯 Final Thoughts&lt;/strong&gt;&lt;br&gt;
With just a few annotations and the right architecture, Spring Boot makes transaction management seamless. Whether you're building a simple app or a distributed enterprise system, transactions help ensure your data stays reliable and consistent.&lt;/p&gt;

&lt;p&gt;By understanding how @Transactional works and how to structure your service layers properly, you can build robust applications that fail gracefully.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>java</category>
      <category>api</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Abdulfatai Abdulwasiu Aremu</dc:creator>
      <pubDate>Fri, 16 May 2025 00:59:57 +0000</pubDate>
      <link>https://dev.to/wastech/-37i5</link>
      <guid>https://dev.to/wastech/-37i5</guid>
      <description></description>
      <category>discuss</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Design Patterns in Spring: Making Your Code Elegant and Maintainable</title>
      <dc:creator>Abdulfatai Abdulwasiu Aremu</dc:creator>
      <pubDate>Thu, 24 Apr 2025 19:06:01 +0000</pubDate>
      <link>https://dev.to/wastech/design-patterns-in-spring-making-your-code-elegant-and-maintainable-1g3</link>
      <guid>https://dev.to/wastech/design-patterns-in-spring-making-your-code-elegant-and-maintainable-1g3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Imagine you're building a house. Would you start hammering nails without a blueprint? Probably not. You'd use proven architectural designs to ensure the house is strong, scalable, and easy to maintain.&lt;br&gt;
Software development is no different. We use design patterns proven solutions to recurring problems to make our applications more structured and maintainable. And if you're working with Spring Framework, you're already using some of these patterns, whether you realize it or not!&lt;br&gt;
In this article, we'll explore essential design patterns used in Spring, how they work, and why they matter. We'll break them down with relatable analogies and real-world examples.&lt;br&gt;
&lt;strong&gt;1. Singleton Pattern – The One and Only&lt;/strong&gt;&lt;br&gt;
What is it?&lt;br&gt;
The Singleton Pattern ensures that a class has only one instance and provides a global access point to it.&lt;br&gt;
Where is it used in Spring?&lt;br&gt;
In Spring’s Bean Scope, by default, all beans are Singletons. That means Spring creates only one instance of a bean and reuses it throughout the application.&lt;br&gt;
Real-world analogy:&lt;br&gt;
Think of a president of a country. There is only one at a time, and everyone relies on that one leader. Similarly, Spring keeps a single instance of a bean for efficiency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
@Component
public class AppConfig {
    public AppConfig() {
        System.out.println("Singleton Bean Initialized");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This bean is automatically a singleton. Spring ensures that only one instance of AppConfig is created.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Factory Pattern – The Master Builder&lt;/strong&gt;&lt;br&gt;
What is it?&lt;br&gt;
The Factory Pattern provides a way to create objects without specifying their exact class.&lt;br&gt;
Where is it used in Spring?&lt;br&gt;
Spring’s BeanFactory and ApplicationContext follow the Factory Pattern by creating and managing beans.&lt;br&gt;
Real-world analogy:&lt;br&gt;
Imagine a car factory where you order a car, but you don’t build it yourself. The factory takes care of the complex assembly. Similarly, Spring creates and configures objects for you.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Configuration
public class AppConfig {
    @Bean
    public Car getCar() {
        return new Car("Tesla Model X");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, Spring acts as a factory and provides an instance of Car when needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Proxy Pattern – The Bodyguard&lt;/strong&gt;&lt;br&gt;
What is it?&lt;br&gt;
A Proxy Pattern provides an object that acts as a substitute for another object, controlling access to it.&lt;br&gt;
Where is it used in Spring?&lt;br&gt;
Spring uses proxies in AOP (Aspect-Oriented Programming) and Transaction Management.&lt;br&gt;
Real-world analogy:&lt;br&gt;
A celebrity’s bodyguard screens people before they reach the celebrity. Similarly, proxies can restrict, enhance, or log interactions before reaching the actual object.&lt;br&gt;
Example (AOP Proxy):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Aspect
@Component
public class LoggingAspect {
    @Before("execution(* com.example.service.*.*(..))")
    public void logMethodCall() {
        System.out.println("Method is being called");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, an AOP proxy intercepts method calls and logs them before execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Template Method Pattern – The Recipe&lt;/strong&gt;&lt;br&gt;
What is it?&lt;br&gt;
The Template Method Pattern defines the skeleton of an algorithm and lets subclasses fill in specific details.&lt;br&gt;
Where is it used in Spring?&lt;br&gt;
Spring’s JdbcTemplate, RestTemplate, and TransactionTemplate follow this pattern.&lt;br&gt;
Real-world analogy:&lt;br&gt;
Think of a cooking recipe. The general steps (boil water, add ingredients, cook) remain the same, but the specific ingredients and spices can vary.&lt;br&gt;
Example (JdbcTemplate):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Autowired
private JdbcTemplate jdbcTemplate;

public void saveUser(User user) {
    String sql = "INSERT INTO users (name, email) VALUES (?, ?)";
    jdbcTemplate.update(sql, user.getName(), user.getEmail());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, JdbcTemplate handles database interactions so you don’t have to write boilerplate JDBC code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Observer Pattern – The News Reporter&lt;/strong&gt;&lt;br&gt;
What is it?&lt;br&gt;
The Observer Pattern allows objects (observers) to listen for changes in another object (subject).&lt;br&gt;
Where is it used in Spring?&lt;br&gt;
Spring’s ApplicationEventPublisher follows this pattern to enable event-driven programming.&lt;br&gt;
Real-world analogy:&lt;br&gt;
A news channel broadcasts updates. Subscribers (observers) receive the updates when something new happens.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component
public class UserCreatedEvent extends ApplicationEvent {
    public UserCreatedEvent(Object source) {
        super(source);
    }
}
&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;
@Component
public class UserCreatedListener implements ApplicationListener&amp;lt;UserCreatedEvent&amp;gt; {
    @Override
    public void onApplicationEvent(UserCreatedEvent event) {
        System.out.println("User created event received");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, UserCreatedListener listens for UserCreatedEvent and takes action when it occurs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Spring makes heavy use of design patterns to ensure clean, scalable, and efficient code. Whether it's Singletons for efficiency, Factories for object creation, Proxies for security, Template Methods for reducing boilerplate, or Observers for event-driven programming, these patterns help developers build robust applications effortlessly.&lt;br&gt;
By understanding these patterns, you can write better, more maintainable Spring applications and appreciate the elegance of Spring’s design. Next time you write a Spring application, take a moment to recognize these patterns at work!&lt;br&gt;
&lt;em&gt;Happy coding! 🚀&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>java</category>
      <category>springboot</category>
    </item>
  </channel>
</rss>
