<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sabarinathan Ramanathan on Medium]]></title>
        <description><![CDATA[Stories by Sabarinathan Ramanathan on Medium]]></description>
        <link>https://medium.com/@sabarinathan.code?source=rss-344bc6b99451------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*bTyeBauaP6fMrMP9</url>
            <title>Stories by Sabarinathan Ramanathan on Medium</title>
            <link>https://medium.com/@sabarinathan.code?source=rss-344bc6b99451------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:51:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sabarinathan.code/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Who Should Control Your Objects in Flutter? Singleton vs Factory vs Flyweight]]></title>
            <link>https://medium.com/@sabarinathan.code/who-should-control-your-objects-in-flutter-singleton-vs-factory-vs-flyweight-5f61cb91fc6e?source=rss-344bc6b99451------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f61cb91fc6e</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Sabarinathan Ramanathan]]></dc:creator>
            <pubDate>Fri, 13 Feb 2026 10:44:01 GMT</pubDate>
            <atom:updated>2026-02-14T04:57:20.490Z</atom:updated>
            <content:encoded><![CDATA[<p>When we talk about Flutter architecture, we usually think about widgets, state management, and folder structure. But there is a deeper layer that decides whether your app stays scalable or slowly becomes fragile.</p><p>That layer is <strong>object control</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*heBFFDjAnLZ0ocyPslB8bA.png" /></figure><p>It’s been 1 year and 3 months since I started my career. When I entered the industry, I was confident in my problem-solving skills. If you gave me a logical problem, I knew I could solve it.</p><p>But real-world application development taught me something important:</p><p><strong>Software development is not just about solving problems.<br>It’s about designing systems.</strong></p><p>A big change in my thinking happened because of my architect and manager, <strong>Ishwar</strong>.</p><p>He is the architect of our app while also handling the manager role. He introduced me to design patterns — not as theory, but as a way to think about object ownership, lifecycle, and responsibility.</p><p>Before that, I focused only on logic.<br>He helped me understand architecture.</p><p>And the most important realization was this:</p><p><strong>Architecture is not about creating objects.<br>It’s about controlling them.</strong></p><p>It depends on:</p><p>• Who creates the object<br>• Who owns the object<br>• How long it lives<br>• Whether it should be reused</p><p>This is where Singleton, Factory, Flyweight, and Riverpod become essential.</p><p>Not as theory.<br>But as real architectural tools.</p><h3>Every Flutter App Constantly Creates Objects</h3><p>In every Flutter app, objects are created all the time:</p><p>• API services<br>• Repositories<br>• Controllers<br>• State holders<br>• Models<br>• Configurations</p><p>If these objects are not controlled properly, the system becomes fragile.</p><p>Not because Flutter is weak.</p><p>But because ownership is unclear.</p><p>Every object must answer four questions:</p><p>• Who creates me?<br>• Who owns me?<br>• How long should I live?<br>• Can I be reused?</p><p>Singleton, Factory, and Flyweight answer these questions.</p><p>Riverpod helps enforce these answers safely.</p><h3>Problem 1: Identity Control (Singleton)</h3><p>Some objects must have only one instance.</p><p>Examples:</p><p>• ApiService holding auth token<br>• Session manager<br>• Analytics service</p><p>Example without control:</p><pre>class ApiService {<br>  String token = &#39;&#39;;<br>}</pre><pre>final api1 = ApiService();<br>final api2 = ApiService();</pre><pre>api1.token = &quot;UserA&quot;;<br>api2.token = &quot;UserB&quot;;</pre><p>Now there are two different identities.<br>This creates inconsistency.</p><p>Singleton solves this:</p><pre>class ApiService {<br>  ApiService._();</pre><pre>  static final ApiService _instance = ApiService._();</pre><pre>  factory ApiService() =&gt; _instance;</pre><pre>  String token = &#39;&#39;;<br>}</pre><p>Now only one instance exists.</p><p>Singleton answers:</p><p><strong>Who owns this object? → The application</strong></p><h3>Problem 2: Creation Control (Factory)</h3><p>As apps grow, object creation becomes conditional.</p><p>Example:</p><p>• Dev → Mock repository<br>• Prod → Real repository<br>• Test → Fake repository</p><p>Bad approach:</p><pre>if (isDev) {<br>  repo = MockRepo();<br>} else {<br>  repo = ApiRepo(ApiService());<br>}</pre><p>Now UI controls creation.</p><p>This breaks architecture.</p><p>Factory solves this:</p><pre>class UserRepositoryFactory {<br>  static UserRepository create(bool isDev) {<br>    if (isDev) {<br>      return MockUserRepository();<br>    }<br>    return ApiUserRepository(ApiService());<br>  }<br>}</pre><p>Factory answers:</p><p><strong>Who creates the object? → Architecture layer</strong></p><p>Not UI.</p><h3>Problem 3: Reuse Control (Flyweight)</h3><p>Flutter rebuilds frequently.</p><p>Without reuse, identical objects are created again and again.</p><p>Example:</p><pre>Avatar(user.image)<br>Avatar(user.image)<br>Avatar(user.image)</pre><p>Flyweight solves reuse:</p><pre>class AvatarFactory {<br>  static final Map&lt;String, Avatar&gt; cache = {};</pre><pre>  static Avatar get(String url) {<br>    return cache.putIfAbsent(url, () =&gt; Avatar(url));<br>  }<br>}</pre><p>Now objects are reused safely.</p><p>Flyweight answers:</p><p><strong>Can this object be reused? → Yes</strong></p><p>Flutter already uses this internally with:</p><p>• const widgets<br>• TextStyle<br>• IconData<br>• ThemeData</p><h3>How Riverpod Controls All of This</h3><p>Riverpod is not just state management.</p><p>Riverpod is an <strong>object lifecycle controller</strong>.</p><p>When using Riverpod code generation:</p><pre>@riverpod<br>ApiService apiService(ApiServiceRef ref) {<br>  return ApiService();<br>}</pre><p>Riverpod now controls:</p><p>• Creation<br>• Sharing<br>• Lifecycle</p><p>This behaves like a safe Singleton.</p><h3>Riverpod as Factory</h3><pre>@riverpod<br>UserRepository userRepository(UserRepositoryRef ref) {<br>  final api = ref.watch(apiServiceProvider);<br>  final isDev = ref.watch(environmentProvider);</pre><pre>  if (isDev) {<br>    return MockUserRepository();<br>  }</pre><pre>  return ApiUserRepository(api);<br>}</pre><p>Riverpod acts as Factory.</p><p>UI does not create objects.</p><p>Architecture controls creation.</p><h3>Riverpod as Flyweight</h3><pre>@riverpod<br>Avatar avatar(AvatarRef ref, String url) {<br>  return Avatar(url);<br>}</pre><p>Riverpod reuses objects safely.</p><p>Memory usage becomes efficient.</p><h3>The Most Important Shift in Thinking</h3><p>Earlier, I used to think:</p><p>“I need this object, so I will create it.”</p><p>Now I think:</p><p><strong>Who should control this object?</strong></p><p>That question defines architecture quality.</p><p>Singleton protects identity.<br>Factory protects creation.<br>Flyweight protects reuse.<br>Riverpod controls lifecycle.</p><h3>Final Thought</h3><p>Flutter apps become scalable when object control becomes intentional.</p><p>Not accidental.</p><p>This was one of the most valuable lessons I learned under Ishwar’s guidance.</p><p>Design patterns are not about clever code.</p><p>They are about ownership and responsibility.</p><p>Because scalable software is not built by creating objects.</p><p>It is built by controlling them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f61cb91fc6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Virtualization vs Lazy Loading vs Pagination in Mobile Development
Clearing the Terminology…]]></title>
            <link>https://medium.com/@sabarinathan.code/virtualization-vs-lazy-loading-vs-pagination-in-mobile-development-clearing-the-terminology-538bc1b2dc2f?source=rss-344bc6b99451------2</link>
            <guid isPermaLink="false">https://medium.com/p/538bc1b2dc2f</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Sabarinathan Ramanathan]]></dc:creator>
            <pubDate>Fri, 23 Jan 2026 17:29:58 GMT</pubDate>
            <atom:updated>2026-01-28T19:30:27.332Z</atom:updated>
            <content:encoded><![CDATA[<h3>Virtualization vs Lazy Loading vs Pagination in Mobile Development -<br>Clearing the Terminology Confusion (With Flutter Examples)</h3><p><em>A casual conversation with my colleague and friend, </em><strong><em>Jegadeesh</em></strong><em>, sparked this investigation. While discussing Flutter lists, we referred to </em><em>ListView.builder as lazy loading—making me realize I had been confusing it with </em><strong><em>UI virtualization</em></strong><em>. This article is the result of that realization, with thanks to </em><strong><em>Jegadeesh</em></strong><em> for prompting the deeper dive.</em></p><h3>Why This Topic Matters</h3><p>In mobile development — especially when building feeds, chats, or large lists — developers often use terms like <strong>virtualization</strong>, <strong>lazy loading</strong>, and <strong>pagination</strong> interchangeably. This leads to confusion, particularly in the Flutter ecosystem, where many developers say things like:</p><p>“ListView.builder uses lazy loading.”</p><p>While this phrasing is common, it is not technically accurate.</p><p>Mobile devices have limited memory, limited CPU/GPU power, and network constraints. Rendering too many UI elements at once can cause janky scrolling, loading too much data at once can lead to memory issues, and fetching everything eagerly can slow down app startup.</p><p>To solve these problems, mobile frameworks rely on three different techniques, each solving a different problem:</p><ul><li><strong>Virtualization</strong> — UI rendering optimization</li><li><strong>Lazy Loading</strong> — when data is fetched</li><li><strong>Pagination</strong> — how much data is fetched</li></ul><p>These are not alternatives. They are designed to work together.</p><h3>1. Virtualization (UI / Rendering Layer)</h3><p><strong>Virtualization</strong> means rendering only the UI elements that are currently visible on the screen. Off-screen elements are not built, or they are disposed and reused.</p><p>What virtualization delays:</p><ul><li>Widget creation</li></ul><p>What it does not delay:</p><ul><li>Data fetching</li></ul><p>In Flutter, virtualization is built into scrolling widgets such as ListView.builder, GridView.builder, and Slivers.</p><p>Example:</p><pre>ListView.builder(<br>  itemCount: items.length,<br>  itemBuilder: (context, index) {<br>    return ListTile(<br>      title: Text(items[index]),<br>    );<br>  },<br>);</pre><p>Internally, Flutter builds widgets only for visible items, reuses elements as the user scrolls, keeps memory usage low, and ensures smooth scrolling performance.</p><p>The term <strong>virtualization</strong> should be used when discussing UI performance, rendering optimization, or framework behavior.</p><p>Correct usage:<br>Flutter uses virtualization to render only visible list items.</p><h3>2. Lazy Loading (Data Loading Strategy)</h3><p><strong>Lazy loading</strong> means loading data or resources only when they are actually needed. It is usually triggered by user interaction, scrolling, or navigation.</p><p>What lazy loading delays:</p><ul><li>Data fetching</li></ul><p>What it does not delay:</p><ul><li>Widget rendering</li></ul><p>In a scrolling list, lazy loading is often implemented by detecting when the user reaches near the bottom of the list and then fetching more data.</p><p>Lazy loading is commonly applied to:</p><ul><li>API responses</li><li>Database records</li><li>Images</li><li>Files</li></ul><p>The term <strong>lazy loading</strong> should be used when discussing network optimization, API calls, or memory usage.</p><p>Correct usage:<br>We use lazy loading to fetch more data when the user scrolls.</p><h3>3. Pagination (Data Size Control)</h3><p><strong>Pagination</strong> means splitting a large dataset into fixed-size chunks, commonly called pages.</p><p>Example:</p><ul><li>Page 1 → 20 items</li><li>Page 2 → 20 items</li><li>Page 3 → 20 items</li></ul><p>Example API usage:</p><pre>fetchPosts(page: 2, limit: 20);</pre><p>Common types of pagination include:</p><ul><li>Offset-based pagination (page number)</li><li>Cursor-based pagination (last item ID)</li><li>Time-based pagination</li></ul><p>The term <strong>pagination</strong> should be used when discussing backend APIs, network payload size, or data limits.</p><p>Correct usage:<br>The API supports pagination with 20 items per page.</p><h3>Key Differences at a Glance</h3><p><strong>Virtualization</strong><br>Layer: UI<br>Purpose: Smooth rendering<br>Delays: Widget creation</p><p><strong>Lazy Loading</strong><br>Layer: Data<br>Purpose: Load data on demand<br>Delays: Data fetching</p><p><strong>Pagination</strong><br>Layer: Data<br>Purpose: Control data size<br>Delays: Amount of data returned</p><h3>How They Work Together (Real-World Flow)</h3><p>Consider a social media feed:</p><ul><li>The user opens the app</li><li>The first page of data is fetched using pagination</li><li>The list renders only visible items using virtualization</li><li>The user scrolls</li><li>When the user reaches near the bottom, lazy loading triggers</li><li>The next page is fetched using pagination</li><li>The UI continues rendering efficiently using virtualization</li></ul><h3>Why Flutter Developers Call ListView.builder “Lazy Loading”</h3><p>In the Flutter community, developers often say that ListView.builder uses lazy loading. This wording is common but technically imprecise.</p><p>ListView.builder does not lazy load data. The data must already exist in memory. What it actually does is <strong>lazily build widgets</strong> as they become visible on screen.</p><p>This behavior is more accurately described as <strong>UI virtualization</strong>.</p><p>The confusion exists because both behaviors:</p><ul><li>Happen during scrolling</li><li>Delay work until needed</li><li>Improve performance</li></ul><p>However, they delay different things:</p><ul><li>Virtualization delays widget creation</li><li>Lazy loading delays data fetching</li></ul><p>Using “lazy loading” for ListView.builder is acceptable in casual conversation, but it is not precise in technical discussions.</p><p>A more accurate statement would be:</p><p>ListView.builder virtualizes the UI by lazily building widgets, while data is lazy loaded separately using pagination.</p><h3>Common Incorrect Statements</h3><ul><li>Lazy loading improves UI rendering</li><li>Pagination replaces virtualization</li><li>ListView.builder loads data lazily</li></ul><p>All of these statements are incorrect.</p><h3>Correct Professional Statement</h3><p>Flutter uses virtualization for efficient UI rendering, while lazy loading combined with pagination is used for efficient data fetching.</p><h3>Interview-Ready One-Line Answer</h3><p>Virtualization optimizes UI rendering, lazy loading decides when data is fetched, and pagination controls how much data is fetched.</p><h3>Final Takeaway</h3><ul><li>Virtualization is a UI concern</li><li>Lazy loading is about data timing</li><li>Pagination is about data size</li></ul><p>They solve different problems and are meant to be used together.</p><p>What started as a simple conversation helped clarify a common misconception. Understanding this distinction not only improves technical accuracy, but also helps developers communicate better and design scalable mobile apps.</p><blockquote>I went in to understand virtualization…<br>somehow came out questioning Singleton vs Flyweight 😅<br>Same confusion. Different intent.<br>And yeah — this one deserves its own breakdown 👀<br>Stay tuned 😉</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=538bc1b2dc2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>