<?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 Rob Paul on Medium]]></title>
        <description><![CDATA[Stories by Rob Paul on Medium]]></description>
        <link>https://medium.com/@robpaulblog?source=rss-9daef450d58b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nIq27qKl-lDBgofZStnhrg@2x.jpeg</url>
            <title>Stories by Rob Paul on Medium</title>
            <link>https://medium.com/@robpaulblog?source=rss-9daef450d58b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 21:40:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@robpaulblog/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[Operational Characteristics in Application Design]]></title>
            <link>https://robpaulblog.medium.com/operational-characteristics-in-application-design-770f5e93f1c9?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/770f5e93f1c9</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 11:44:58 GMT</pubDate>
            <atom:updated>2025-04-17T11:44:58.262Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s get straight into this. I know it’s a dull article about Operational Architecture characteristics, but it is crucial to learn about this when developing or creating an application. However, operational components are essential. You wouldn’t want to spend so much time on your application that it fails to stay running or gets hacked. A beautifully engineered website will provide no value to anyone if it takes too long to load.</p><p><strong>What are Operational Architectural Characteristics?</strong></p><p><strong>Availability</strong></p><ul><li><strong>Definition</strong>: Availability refers to the duration an application needs to function. It is a great product, but poor availability diminishes its value.</li><li><strong>Key Aspects</strong>: Uptime and downtime of the application.</li><li><strong>Influencing factors</strong>: Hardware failures, software bugs, network issues, human errors, scheduled maintenance.</li><li><strong>How to spot</strong>: If you are a small blog site, you might want to have more downtime than if you are Amazon, which will want as little downtime as possible.</li></ul><p><strong>Continuity performance</strong></p><ul><li><strong>Definition:</strong> Maintaining essential application functions and service levels at an acceptable standard <em>during and after</em> disruptions. It’s about keeping critical operations going.</li><li><strong>Key Aspects:</strong> Focuses on keeping <em>critical</em> functions running (potentially degraded), predefined acceptable levels of service during disruption, resilience, and quick recovery of key functions (short RTO for critical).</li><li><strong>Influencing Factors:</strong> Strong BCP/DR plans, redundancy, failover, fault tolerance, network resilience, data replication, and testing.</li><li><strong>How to Spot:</strong> Observe if <em>critical</em> tasks still work during partial outages, look for graceful handling of minor issues, communication about the status of <em>key functions</em> during incidents, and architectural signs of redundancy. It’s about sustained <em>essential</em> operations, not just overall uptime.</li></ul><p><strong>Recoverability</strong></p><ul><li><strong>Definition:</strong> The application can<strong> restore itself to a fully functional state after a failure or disruption</strong> within a defined timeframe and with minimal data loss. It’s about getting back online quickly and thoroughly.</li><li><strong>Key Aspects:</strong> Focuses on <strong>speed of restoration (RTO)</strong>, <strong>amount of data loss (RPO)</strong>, effective backup and restore procedures, and well-tested disaster recovery plans.</li><li><strong>Influencing Factors:</strong> Do you have a backup system that can efficiently restore processes, automated recovery tools, thorough testing of recovery procedures, data replication strategies, and skilled recovery teams?</li><li><strong>How to Spot:</strong> Look for evidence of regular backups (frequency, retention), documented and tested restore procedures, short recovery times after simulated or actual failures, minimal data loss during recovery, and automated recovery mechanisms. Observe quick return to full functionality after an incident.</li></ul><p><strong>Reliability</strong></p><ul><li><strong>Definition:</strong> Probability of the application performing as required without failure for a specified period.</li><li><strong>Key Aspects:</strong> Consistency, low failure rate, long Mean Time Between Failures (MTBF).</li><li><strong>Influencing Factors:</strong> Quality of code, thorough testing, stable infrastructure, proper maintenance, robust design.</li><li><strong>How to Spot:</strong> Few bugs or crashes were reported, but there was consistent performance over time and long periods without needing restarts or fixes.</li></ul><p><strong>Robustness</strong></p><ul><li><strong>Definition:</strong> The application’s ability to maintain functionality despite unexpected or adverse conditions. As a software engineer, you should always look for how robust your code is.</li><li><strong>Key Aspects:</strong> Graceful error handling, input validation, resilience to stress/attacks, fault tolerance.</li><li><strong>Influencing Factors:</strong> Comprehensive error handling logic, strong input validation, security measures, redundancy, and well-defined failure modes.</li><li><strong>How to Spot:</strong> Application doesn’t crash with invalid input, recovers from errors without data loss, remains stable under heavy load or attack attempts.</li></ul><p><strong>Scalability</strong></p><ul><li><strong>Definition:</strong> The application’s ability to handle increasing workload or demand without significant performance degradation.</li><li><strong>Key Aspects:</strong> handling more users or data while maintaining performance under load, as well as ensuring efficient resource utilization, either by scaling up or down.</li><li><strong>Influencing Factors: </strong>Architectural design, what database design you have chosen, effective load balancing, auto-scaling capabilities, and the strategies you have in place for your resource management.</li><li><strong>How to Spot:</strong> Check if the application maintains consistent performance as user load increases, whether resources can be easily added or removed, and whether response times remain acceptable during peak usage.</li></ul><p>Picture you’re working on a banking application process, handling millions of financial transactions daily. High reliability is crucial to prevent a whole load of problems. You would like to think the data integrity is secure. Robust recoverability mechanisms should be in place to quickly restore the system and minimize data loss in case of any failures, maintaining customer trust and regulatory compliance. Let’s dive into how we would do this in Azure.</p><p>For asynchronous tasks related to transactions (e.g., logging, notifications), Azure Service Bus with transactional support ensures that messages are delivered reliably and exactly once, even if components fail during processing. We can also handle the database across multiple Azure Availability Zones within a region provides resilience to datacenter-level failures. Data is synchronously replicated across these zones.</p><p>To handle the Robustness we can use geo-replication to a secondary Azure region. This creates a continuously synchronized, readable secondary database that can be failed over to in case of a regional disaster. Automated Backups with Azure SQL Database, this will protect our data. Nevertheless, we still need to be sure that the code is going to handle all the error cases gracefully for everything to work. This would be down to having correct testing and error handling.</p><p>Handling operational characteristics can be the difference between a fragile and dependable application. So, take these principles to heart in your next project and build something resilient.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=770f5e93f1c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeORM Entities for a Multilingual Crossword App]]></title>
            <link>https://robpaulblog.medium.com/typeorm-entities-for-a-multilingual-crossword-app-8330a216c71e?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8330a216c71e</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[better-code]]></category>
            <category><![CDATA[typeorm]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Tue, 04 Mar 2025 21:46:26 GMT</pubDate>
            <atom:updated>2025-03-04T21:46:26.114Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered how a language-learning crossword app stores its data efficiently, supports multiple languages, and tracks user progress?</p><p>A multilingual crossword puzzle application, presented us with this very challenge. In this article, we’ll dive into the how to design a crossword TypeORM schema that powers its database. We’ll uncover the design decisions behind our entities and see how they work together to manage a wealth of linguistic data.</p><p><strong>Core Entities: The Building Blocks</strong></p><p>I haven’t shared all of the Schemas with you, only the main ones to get the gist of the schemas. I’ve gone for the main once&#39;s - crosswords, Languages and words.</p><pre>@Entity()<br>export class Languages {<br> @PrimaryGeneratedColumn({ comment: &quot;The unique identifier for this language.&quot; })<br> language_id: number;<br><br> @Column({<br>  type: &quot;enum&quot;,<br>  enum: LanguageCode,<br>  comment: &quot;The short code for the language .&quot;,<br> })<br> language_code: LanguageCode;<br><br> @Column({<br>  type: &quot;enum&quot;,<br>  enum: LanguageName,<br>  comment: &quot;The full name of the language &quot;,<br> })<br> language_name: LanguageName;<br><br> @OneToMany(() =&gt; Words, (word) =&gt; word.language)<br> /**<br>  * One-to-many relationship with `Words`. One language can have multiple words.<br>  */<br> words: Words[];<br><br> @OneToMany(() =&gt; Crossword, (crossword) =&gt; crossword.language)<br> /**<br>  * One-to-many relationship with `Crossword`. One language can have multiple crosswords.<br>  */<br> crosswords: Crossword[];<br><br> @OneToMany(() =&gt; Topic, (topic) =&gt; topic.language)<br> /**<br>  * One-to-many relationship with `Topic`. One language can have multiple topics.<br>  */<br> topics: Topic[];<br>}</pre><pre><br>@Entity()<br>export class Words {<br> @PrimaryGeneratedColumn({ comment: &quot;The unique identifier for this word.&quot; })<br> word_id: number;<br><br> @ManyToOne(<br>  () =&gt; Languages,<br>  (language) =&gt; language.words,<br>  { onDelete: &quot;CASCADE&quot; },<br> )<br> @JoinColumn({ name: &quot;language_id&quot; })<br> @Index(&quot;idx_words_language_id&quot;)<br> /**<br>  * Foreign key to the Languages table. Represents the language of this word.<br>  */<br> language: Languages;<br><br> @Column({<br>  unique: true,<br>  type: &quot;citext&quot;,<br>  comment: &quot;The text of the word.&quot;,<br> })<br> word_text: string;<br><br> @Column({<br>  type: &quot;citext&quot;,<br>  unique: true,<br>  comment: &quot;The definition of the word.&quot;,<br> })<br> definition: string;<br><br> @Column({<br>  default: false,<br>  comment: &quot;Whether this word is valid for Wordle.&quot;,<br> })<br> wordle_valid: boolean;<br><br> @OneToMany(<br>  () =&gt; CrosswordWord,<br>  (crosswordWord) =&gt; crosswordWord.words,<br> )<br> /**<br>  * One-to-many relationship with CrosswordWord. One word can appear in multiple crosswords.<br>  */<br> crosswordWords: CrosswordWord[];<br>}</pre><pre>@Entity()<br>export class Crossword {<br> @PrimaryGeneratedColumn({ comment: &quot;The unique identifier for this crossword.&quot; })<br> crossword_id: number;<br><br> @ManyToOne(<br>  () =&gt; Languages,<br>  (language) =&gt; language.crosswords,<br>  { onDelete: &quot;CASCADE&quot; },<br> )<br> @JoinColumn({ name: &quot;language_id&quot; })<br> /**<br>  * Foreign key for the `Languages` table. The language in which the crossword is.<br>  */<br> language: Languages;<br><br> @Column({ type: &quot;citext&quot;, unique: true, comment: &quot;The title of the crossword puzzle.&quot; })<br> title: string;<br><br> @Column({<br>  type: &quot;timestamptz&quot;,<br>  default: () =&gt; &quot;CURRENT_TIMESTAMP&quot;,<br>  comment: &quot;The date and time the crossword was created.&quot;,<br> })<br> date_created: Date;<br><br> @Column({ comment: &quot;The difficulty level of the crossword.&quot; })<br> difficulty: number;<br><br> @Column({<br>  type: &quot;boolean&quot;,<br>  default: true,<br>  comment: &quot;Indicates whether this crossword is publicly available.&quot;,<br> })<br> is_Public: boolean;<br><br> @OneToMany(<br>  () =&gt; CrosswordWord,<br>  (crosswordWord) =&gt; crosswordWord.crossword,<br> )<br> /**<br>  * One-to-many relationship with CrosswordWord. One crossword can have multiple words.<br>  */<br> crosswordWords: CrosswordWord[];<br><br> @OneToMany(<br>  () =&gt; UserCrossword,<br>  (userCrossword) =&gt; userCrossword.crossword,<br> )<br> /**<br>  * One-to-many relationship with `UserCrossword`. One crossword can be attempted by many users.<br>  */<br> userCrosswords: UserCrossword[];<br><br> @ManyToMany(() =&gt; Topic)<br> @JoinTable({<br>  name: &quot;crossword_topics&quot;,<br>  joinColumn: { name: &quot;crossword_id&quot;, referencedColumnName: &quot;crossword_id&quot; },<br>  inverseJoinColumn: { name: &quot;topic_id&quot;, referencedColumnName: &quot;topic_id&quot; },<br> })<br> /**<br>  * Many-to-many relationship with Topic. One crossword can have multiple topics.<br>  */<br> topics: Topic[];<br>}</pre><p><strong>III. Key Design Decisions: Building for Flexibility and Efficiency</strong></p><ul><li><strong>Case-Insensitive Text with </strong><strong>citext:</strong> I chose the citext extension for word_text, definition, and topic_name. This ensures that we can perform case-insensitive searches and maintain a clean database, preventing duplicate entries with different capitalization.</li><li><strong>Enums for </strong><strong>LanguageCode and </strong><strong>LanguageName:</strong> We used TypeORM enums for language_code and language_name to restrict the possible values. This greatly improves data integrity.</li><li><strong>Join Tables:</strong> The CrosswordWord and UserCrossword entities are <em>join tables</em> that help us model many-to-many relationships cleanly and efficiently.</li><li><strong>CrosswordWord for Clues:</strong> CrosswordWord links words to crosswords and has a clue field. This allows us to store clues specific to a word in a particular crossword, allowing for great flexibility.</li><li><strong>Composite Unique Constraint in </strong><strong>CrosswordWord</strong>: The unique constraint (@Unique([&quot;crossword&quot;, &quot;words&quot;])) prevents the same word from being used more than once in the same crossword.</li><li><strong>Foreign Key Constraints with </strong><strong>ON DELETE CASCADE:</strong> Relationships like ManyToOne are defined with ON DELETE CASCADE. This means if we delete a Language, for example, all the related Words, Topics and Crossword are automatically deleted, maintaining data integrity.</li><li><strong>Index</strong>: We use indexes to speed up the queries.</li><li><strong>Default Values</strong>: Using default: true and default: () =&gt; &quot;CURRENT_TIMESTAMP&quot; helps to add default values, improving the data entry process.</li><li><strong>The order of the migrations</strong>: By having the migrations in a specific order, we ensure that the tables are created in the correct order.</li></ul><p>One thing I really value is how my file’s entity definitions act as built-in documentation. It’s reassuring to know that even months later, I can easily understand the schema just by looking at the code. Plus, TypeORM’s migration generator has been a huge time-saver. It handles about 95% of the migration code, leaving me with just a few minor adjustments like adding external packages and defining language enums. It’s been incredibly efficient.</p><p>There are still more neat addons I can add with typeorm which will come in handy. I’ll keep you posted, here is a link to the repo to have a deeper browse. <a href="https://github.com/Robert-maker1994">https://github.com/Robert-maker1994</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8330a216c71e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Compose and Dockerfiles: Simplifying Multi-Container Applications]]></title>
            <link>https://robpaulblog.medium.com/docker-compose-and-dockerfiles-simplifying-multi-container-applications-903f47ebe7bf?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/903f47ebe7bf</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Mon, 03 Mar 2025 13:16:49 GMT</pubDate>
            <atom:updated>2025-03-03T13:16:49.809Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Docker Compose and Dockerfiles: Simplifying Multi-Container Applications</strong></p><p>This article introduces Docker Compose, a tool designed to streamline the management of multi-container Docker applications. We’ll explore its fundamental concepts, explain its advantages, and demonstrate how it simplifies the development and deployment of complex applications.</p><p><strong>Why Docker</strong></p><p>Docker allows developers to package applications and their dependencies into containers, ensuring consistent execution across various environments, whether local or cloud-based.</p><p>In essence, a Docker container acts as a lightweight virtual machine, eliminating the “it works on my machine” problem.</p><p>In a typical web application, you’ll encounter a frontend, a backend, and a database.</p><p>Docker Compose takes their respective Dockerfiles and composes them in one.</p><p>The primary benefit of Docker Compose is its ability to launch and manage multiple containers with a single command. For developers, this simplifies the process of setting up and running complex applications, enhancing productivity.</p><p><strong>Docker Compose Configuration: A Practical Example</strong></p><pre>services:<br>  db:<br>    image: postgres:15<br>    ports:<br>      - &quot;5432:5432&quot;<br>    environment:<br>      POSTGRES_USER: user<br>      POSTGRES_PASSWORD: password<br>      POSTGRES_DB: filemanagement<br>    volumes:<br>      - postgres_data_filesystem:/var/lib/postgresql/data<br>    networks:<br>      - file-system<br><br>backend:<br>    build: ./backend<br>    ports:<br>      - &quot;5001:5001&quot;<br>    depends_on:<br>      - db<br>    healthcheck:<br>      test: curl --fail http://localhost:5001/health || exit 1<br>      interval: 30s<br>      timeout: 10s<br>      retries: 10<br>      start_period: 60s<br>    env_file:<br>      - ./backend/.env<br>    volumes:<br>      - ./backend:/usr/src/app<br>    networks:<br>      - file-system<br>  frontend:<br>    build: ./frontend<br>    ports:<br>      - &quot;8080:8080&quot;<br>    depends_on:<br>      backend:<br>        condition: service_healthy<br>    networks:<br>      - file-system<br>networks:<br>  file-system:<br>volumes:<br>  postgres_data_filesystem:</pre><p>The clarity and readability of Docker Compose’s YAML configuration are significant advantages. This structure simplifies the definition and management of multi-container applications.</p><p><strong>Key Concepts: Networks and Volumes</strong></p><ul><li><strong>Networks:</strong> Docker networks manage communication between containers, the host, and external services. Containers must be connected to a network to establish connectivity. Imagine a network as a dedicated communication channel, ensuring that containers can interact efficiently and securely. For example, the file-system network in the example above allows the frontend, backend, and database to communicate.</li><li><strong>Volumes:</strong> Docker volumes facilitate data sharing between containers. Similar to a shared pantry, volumes provide a persistent storage mechanism. In the example, postgres_data_filesystem ensures that the database data is preserved even if the container is stopped or removed.</li></ul><p><strong>Conclusion</strong></p><p>Docker Compose simplifies the management of multi-container applications by providing a declarative YAML configuration. Its ease of use and being able to run one command docker-compose up . By understanding key concepts like networks and volumes, developers can leverage Docker Compose to streamline their workflows and enhance productivity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=903f47ebe7bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serving Up Software: The Unexpected Parallels Between Chefs and Developers]]></title>
            <link>https://robpaulblog.medium.com/serving-up-software-the-unexpected-parallels-between-chefs-and-developers-1635bd375cf0?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1635bd375cf0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[self]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Sat, 23 Sep 2023 11:31:42 GMT</pubDate>
            <atom:updated>2023-09-23T11:31:42.826Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*C3-E8C4iTmxDmqlxhxUayQ.jpeg" /><figcaption><a href="https://www.istockphoto.com/es/portfolio/bernardbodo?mediatype=photography">bernardbodo</a></figcaption></figure><p>In a bustling city’s heart, as the sun sets, two worlds come alive: the shimmering digital landscape of tech hubs and the aromatic confines of kitchens. At first glance, the chef’s feverish orchestration of dishes might seem worlds apart from a developer’s serene dance of code. Yet, peel back the layers, and you’ll find the two professions simmering together in a pot of shared essence.</p><p>I’ve frequently recalled experiences similar to my life in the kitchen in my software developer career. I’ve found some unexpected parallels between culinary arts and software development.</p><p><strong>The Symphony of Ingredients and Logic</strong> A standout dish is not merely about its star ingredient but how it interplays with many components just as a software application isn’t solely about its core functionality but how it harmoniously integrates with various modules.</p><ul><li><strong>The Main Ingredient/Core Logic</strong>: The chef and the developer prioritize this. It’s the dish’s essence or the solution to a user’s problem.</li><li><strong>Sauce/User Interface (UI)</strong>: The chef’s sauce elevates a dish, making it memorable. Similarly, a well-crafted UI can turn a good app into a great one, elevating the user experience.</li><li><strong>Starch/Backend</strong>: This provides structure. As starch complements a dish’s main ingredient, the backend supports an application’s front end. I for one can’t have a plate of food without a good mostly carb component.</li></ul><p><strong>Foundations: From Mother Sauces to Design Patterns</strong> Chefs swear by the foundational “Five Mother Sauces” of French cuisine, while developers often reference the foundational design patterns established by the Gang of Four. Both serve as building blocks, setting the stage for countless variations and innovations. When learning about the mother sauces, once you understand these foundational patterns, you can derive more specialized solutions that involved adding simplicity and flavour.</p><p><strong>A Pressure Cooker of Challenges</strong> Every profession has its challenges, but the ways chefs and developers address these issues are eerily similar:</p><ul><li><strong>Tackling the Unexpected</strong>: A missing ingredient can throw a chef’s plans into disarray, just as a bug can disrupt a developer’s code. Small things, but the parrels of the problem are the same. Both professionals must think on their feet, often getting creative to find solutions. The same mental model can be applied for tackling a problem.</li><li><strong>Time Crunch</strong>: Be it a kitchen during the dinner rush or a developer during a product launch, managing time and multitasking are essential skills. Urgency in both tasks makes more.</li></ul><p><strong>Constructive Critique: Beyond Taste and Testers</strong> Whether it’s feedback on a dish’s flavour profile or a code review, chefs and developers face critique. Though sometimes hard to digest, this feedback is essential for growth and perfecting the craft. Although, it’s nice to remember that not all constructive Critique should be taken on. You always need to analyse the feedback, I’m not about listening to personal preferences, how I help people understand UI is, the UI is like a med-rare steak. Some people dig that, others would like it well done. There is no right or wrong answer for how to eat steak, I would recommend med-rate. The reason steak melts in your mouth is very valid, however, you want it well done. power to you,</p><p>I’ll have mine med-red.</p><p><strong>Continuous Learning: The Recipe for Success</strong> The culinary world and tech landscape are ever-evolving. For chefs and developers, staying at the top of their game means continuous learning — mastering a new cooking technique or adopting a new programming language. It is a none stop trade moving fast. One year you’re ahead, the next you’re a dinosaur. It can be tricky, exhausting and constant. However, so is life.</p><p><strong>Conclusion</strong>: The crossroads of culinary arts and software engineering highlight a universal truth: Excellence demands passion, adaptability, and continuous learning. Whether blending flavours or fusing code, it’s a relentless pursuit of perfection that crafts masterpieces. So, the next time you savour a dish or use an app, remember: there’s a bit of a chef in every developer and a bit of a developer in every chef.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1635bd375cf0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Command Pattern in TS]]></title>
            <link>https://robpaulblog.medium.com/the-command-pattern-in-ts-e345124d6e24?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e345124d6e24</guid>
            <category><![CDATA[design-thinking]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Mon, 01 May 2023 15:06:49 GMT</pubDate>
            <atom:updated>2023-05-01T16:48:02.109Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Template Method Pattern in TS</h3><p>The Template Method pattern is like a recipe that has some steps you always do and some steps you can change. It helps you keep your code organized and makes changing parts of your “recipe” easier without messing up the whole thing. The problem the pattern addresses is defining the skeleton of an algorithm or process with a specific sequence of steps while allowing some methods to be customizable or extensible.</p><p>Imagine creating Soccer and Basketball subclasses extending a class called Game. They both would have start and end time abstract functions with different logic. However, they would extend an abstract method that would execute a play method calling all the functions in the correct sequence. The benefits of using the Template Method pattern include code organization, reusability, and encapsulation of typical steps in a base class. You can reuse the code across different subclasses.</p><p>This pattern also enforces a contract that the subclass must adhere to, ensuring the same structure in all subclasses.<br>It’s all good, but where would you implement this in the real world? You can apply this pattern anywhere it makes sense. Maybe it won’t work in the codebase you are working on now; however, being a practical software engineer is not about knowing everything but being aware of specific patterns. When you come across a feature that can include the pattern, you can go back and learn more about it.</p><p>Here’s an example of using the Template Method pattern for text processing:</p><pre><br>// Define an abstract class for the text processing algorithm<br>abstract class TextProcessor {<br>    // The template method, which defines the skeleton of the algorithm<br>    processText(input: string): string {<br>      const tokens = this.tokenize(input); // Encapsulating the common step<br>      const processedTokens = this.processTokens(tokens); // Enforcing the contract<br>      return this.generateOutput(processedTokens); // Encapsulating the common step<br>    }<br>  <br>    // Encapsulating the common step: tokenizing the input string<br>    private tokenize(input: string): string[] {<br>      return input.split(&#39; &#39;);<br>    }<br>  <br>    // Enforcing the contract: subclasses must implement this method<br>    abstract processTokens(tokens: string[]): string[];<br>  <br>    // Encapsulating the common step: generating the output string<br>    private generateOutput(tokens: string[]): string {<br>      return tokens.join(&#39; &#39;);<br>    }<br>  }<br>  <br>  // Create a concrete class for a specific text processing implementation (e.g., capitalizing words)<br>  class CapitalizeProcessor extends TextProcessor {<br>    // Implementing the abstract method, providing the specific behavior<br>    processTokens(tokens: string[]): string[] {<br>      return tokens.map(token =&gt; token.charAt(0).toUpperCase() + token.slice(1));<br>    }<br>  }<br>  <br>  // Create a concrete class for another specific text processing implementation (e.g., lowercasing words)<br>  class LowercaseProcessor extends TextProcessor {<br>    // Implementing the abstract method, providing the specific behavior<br>    processTokens(tokens: string[]): string[] {<br>      return tokens.map(token =&gt; token.toLowerCase());<br>    }<br>  }<br>  <br>  // Using the concrete classes to process text<br>  const capitalizeProcessor = new CapitalizeProcessor();<br>  const capitalizedText = capitalizeProcessor.processText(&quot;this is capital and nice.&quot;);<br>  console.log(capitalizedText); // Output: &quot;This Is Capital And nice.&quot;<br>  <br>  const lowercaseProcessor = new LowercaseProcessor();<br>  const lowercasedText = lowercaseProcessor.processText(&quot;This Is Nice Text.&quot;);<br>  console.log(lowercasedText); // Output: &quot;this is nice text.&quot;<br><br><br><br>  </pre><p>There are some drawbacks with the Template Method pattern relies on inheritance, sometimes leading to complex and rigid class hierarchies. If you have a large number of variations or the structure of the algorithm changes frequently, managing subclasses can become cumbersome. It can also bloat your code and be difficult with unit test.</p><p>In conclusion, the Template Method pattern is a powerful tool for structuring your code, promoting reusability and maintainability. Providing a clear separation of concerns between the common and customizable parts of an algorithm enables you to create flexible and extensible solutions. However, it’s essential to be aware of its potential drawbacks, such as rigid class hierarchies and testing challenges. As a software engineer, it’s crucial to understand and recognize the right situations to apply the Template Method pattern and be prepared to explore alternative designs or solutions when needed. By doing so, you’ll be able to create more efficient, robust, and adaptable code, ultimately leading to better software development outcomes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e345124d6e24" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The behavioral Command Pattern]]></title>
            <link>https://robpaulblog.medium.com/the-behavioral-command-pattern-885f1b2392d3?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/885f1b2392d3</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Wed, 29 Mar 2023 08:29:23 GMT</pubDate>
            <atom:updated>2023-03-29T08:29:38.541Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Behavioral Command Pattern</h3><p>The command pattern is a behavioural design pattern — decoupling of the sender and receiver of a request. By encapsulating a request as an object, this pattern enables the parameterisation of clients with different requests, queuing or logging requests and supporting undoable operations. In this article I will delve into the core concepts of the command pattern with an Illustration.</p><p>Imagine you’re playing a game with a friend and you want to give them commands to do something, like go forward, jump, turn left and right. It might get a little tedious telling them what to do always; you can give your friend instructions they can follow whenever you say it.</p><p>So you might say “When I say ‘jump’, you jump” or “When I say ‘go forward’, you move forward”. This way, you can tell them what to do without explaining it every time.</p><p>In computer programming, we use the command pattern to do the same thing. We create commands that can be followed whenever we need to do something.</p><h3>key points</h3><ul><li>The client is the component that is responsible for creating and configuring concrete command objects. It sets up the relationship between the invoker and the commands.</li><li>Command: The interface that defines exectue(), encapsulates the actions and can be called to invoke the actions.</li><li>Invoker: The Invoker is the component that requests the command to be executed.</li><li>Receiver: The component responsible for performing the actual work. It is oblivious to the existence of the command and the invoker.</li></ul><h3>Example</h3><pre>// Define a Receiver that will perform the actual actions<br>class Player {<br>    jump() {<br>      console.log(&quot;Jump!&quot;);<br>    }<br>  <br>    moveForward() {<br>      console.log(&quot;Move forward!&quot;);<br>    }<br>  <br>  }<br>  <br>  // Define a generic command interface that all commands will implement<br>  interface Command {<br>    execute(): void;<br>    undo(): void;<br>  }<br>  <br>  // Define concrete command classes that implement the Command interface and hold a reference to the Receiver<br>  class JumpCommand implements Command {<br>    constructor(private receiver: Player) {}<br>  <br>    execute() {<br>      this.receiver.jump();<br>    }<br>  <br>    undo() {<br>      console.log(&quot;Undo Jump!&quot;);<br>    }<br>  }<br>  <br>  class MoveForwardCommand implements Command {<br>    constructor(private receiver: Player) {}<br>  <br>    execute() {<br>      this.receiver.moveForward();<br>    }<br>  <br>    undo() {<br>      console.log(&quot;Undo Move forward!&quot;);<br>    }<br>  }<br>  <br>  <br>// Define an Invoker that will execute commands<br>class Invoker {<br>    private commandHistory: Command[] = [];<br>    private undoHistory: Command[] = [];<br>  <br>    executeCommand(command: Command) {<br>      command.execute();<br>      this.commandHistory.push(command);<br>    }<br>  <br>    undoLastCommand() {<br>      const lastCommand = this.commandHistory.pop();<br>      if (lastCommand) {<br>        lastCommand.undo();<br>        this.undoHistory.push(lastCommand);<br>      }<br>    }<br>  <br>    redoLastCommand() {<br>      const lastCommand = this.undoHistory.pop();<br>      if (lastCommand) {<br>        lastCommand.execute();<br>        this.commandHistory.push(lastCommand);<br>      }<br>    }<br>  <br>  }<br>  <br>  // Define a client that will create and provide commands to the invoker<br>  class Client {<br>    constructor(private receiver: Player) {}<br>  <br>    createJumpCommand() {<br>      return new JumpCommand(this.receiver);<br>    }<br>  <br>    createMoveForwardCommand() {<br>      return new MoveForwardCommand(this.receiver);<br>    }<br> <br>  }<br>  <br>// Example usage<br>const player = new Player();<br>const client = new Client(player);<br>const invoker = new Invoker();<br>  <br>// Create some commands and execute them<br>const jumpCommand = client.createJumpCommand();<br>const moveForwardCommand = client.createMoveForwardCommand();<br>  <br>invoker.executeCommand(jumpCommand);<br>invoker.executeCommand(moveForwardCommand);<br>  <br>// Undo the last command and print command history<br>invoker.undoLastCommand();<br><br>// Undo and redo the last command, and print command history<br>invoker.undoLastCommand();<br>invoker.redoLastCommand();<br><br>`</pre><p>In this example, we implement a basic command pattern with the Player encapsulating the request to the receiver. The Invoker is set up with a command and triggers its execution. Polymorphism is showcased as the Invoker can work with any object implementing the Command interface. The undo button adds robustness to the code and flexibility for the end user.</p><p>What are the limitations of the pattern? Like most patterns, it increases complexity in the code base, which is unsuitable for simple scenarios, and increases memory overhead, the learning curve of understanding the Command Pattern.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=885f1b2392d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Singleton Pattern in TS]]></title>
            <link>https://robpaulblog.medium.com/singleton-pattern-in-ts-854aa1fe7544?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/854aa1fe7544</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[design-thinking]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 16:58:22 GMT</pubDate>
            <atom:updated>2023-03-16T16:58:22.155Z</atom:updated>
            <content:encoded><![CDATA[<p>The Singleton Pattern is a design pattern that restricts the instantiation of a class to a single instance and ensures that the instance can be easily accessed throughout the entire application. This pattern is used when we need to limit the number of instances of a class to one, such as when a limited amount of a resource needs to be shared across the entire application.</p><p>However, it’s not all sunshine and rainbows, the Singleton Pattern has limitations. It is not thread-safe, meaning that if multiple threads try to access the singleton simultaneously, it can cause issues such as race conditions and inconsistent data. Additionally, if the singleton is not implemented correctly, it can lead to memory leaks and decreased performance.</p><p>To solve this problem, we can use a static method for the getInstance function to address the thread safety issue, such as in the Logger class example below. By making this method static, we ensure that only one class instance is created and accessed throughout the entire application, even in a multi-threaded environment. This is because the static method is only called once, so there is no chance of multiple instances being created.</p><pre>class SharedBook {<br>  private static instance: SharedBook | null = null; // single instance of the book<br>  private notes: string; // notes made by the book owner<br><br>  private constructor() { // private constructor to prevent instantiation<br>    this.notes = &quot;These are some great notes!&quot;; // initialize notes<br>  }<br><br>  public static getInstance(): SharedBook { // static method to get the instance of the book<br>    if (!SharedBook.instance) { // check if the book instance has been created<br>      SharedBook.instance = new SharedBook(); // create the book instance<br>    }<br>    return SharedBook.instance; // return the book instance<br>  }<br><br>  public getNotes(): string { // method to get the notes from the book<br>    return this.notes;<br>  }<br>}<br><br>// Usage:<br>const myBook = SharedBook.getInstance(); // get the instance of the shared book<br>const myNotes = myBook.getNotes(); // get the notes from the shared book<br>console.log(myNotes); // output: These are some great notes!</pre><p>In this TypeScript code example, the SharedBook class represents a book that is shared among friends. The getInstance() method is a static method that creates a single instance of the SharedBook class and returns it. The getNotes() method returns the notes made by the book owner.</p><p>The code ensures that only one instance of the SharedBook class is created and accessed throughout the entire application, just like how there is only one shared book that all friends can access.</p><p>Overall, the Singleton Pattern is a useful design pattern that ensures a single instance of a class is created and easily accessible throughout an application. It can be applied in various places in your code such as a Logger class, a database connection pool, caching, and thread pools. By using this pattern, developers can efficiently manage resources and improve performanc</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=854aa1fe7544" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Factory Pattern in Typescript]]></title>
            <link>https://robpaulblog.medium.com/understanding-the-factory-pattern-in-typescript-381e3955fbc5?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/381e3955fbc5</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[design-patter]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Tue, 07 Mar 2023 10:39:12 GMT</pubDate>
            <atom:updated>2023-09-14T07:45:42.153Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding the Factory Pattern in TS</h3><p><strong>Brief Overview:</strong></p><p>The Factory Pattern is a design pattern. It is a reusable solution to a common programming problem and provides a way to standardize best practices in software development. The Factory Pattern belongs to the creational design pattern category, which is focused on providing mechanisms for object creation. The pattern is used to create objects without specifying the exact class of object that will be created, which makes it more flexible and easier to modify and update code. Overall, the Factory Pattern is an important design pattern that can improve the design and maintainability. In the following sections, we will explore the variations of the Factory Pattern and implementations of the limitations of using this pattern in software development.</p><p><strong>Overview of the Factory Pattern</strong></p><p>The Factory Pattern is a creational design pattern that provides an interface for creating objects in a superclass while allowing subclasses to alter the type of objects that will be created. The Factory Pattern is used when you need to create an object, but you don’t know the exact type of object you need until runtime. The Factory Pattern has several variations, including Simple Factory, Factory Method, and Abstract Factory.</p><p>The Simple Factory Pattern is the most straightforward variation of the Factory Pattern, and it has a single factory method that creates objects of different types based on a given parameter.</p><p>The Factory Method Pattern is more complex and defines an interface for creating objects but allows subclasses to decide which class to instantiate.</p><p>The Abstract Factory Pattern is the most complex variation and provides an interface for creating families of related objects without specifying their concrete classes.</p><p>Object composition can be used in the Factory Pattern to create objects that have complex behaviour by composing simpler objects together. In this pattern, the Factory creates objects by combining smaller objects rather than inheriting behaviour from a parent class.</p><p>The purpose of the pattern is to provide a way to create objects without specifying their exact class. It can prevent code duplication, coupling between code and implementation details and inflexibility. The Factory Pattern can solve these problems by providing a way to centralize object creation and encapsulate the details of the object creation process.</p><p>Example:</p><pre>// Define a base Car interface<br>interface Car {<br>  start(): void;<br>  stop(): void;<br>}<br><br>// Define some concrete car classes that implement the Car interface<br>class SUV implements Car {<br>  start() {<br>    console.log(&#39;SUV started&#39;);<br>  }<br><br>  stop() {<br>    console.log(&#39;SUV stopped&#39;);<br>  }<br>}<br><br>// Define some simpler objects that can be composed <br>// to create more complex Car objects<br>interface Engine {<br>  start(): void;<br>  stop(): void;<br>}<br><br>interface Transmission {<br>  shiftUp(): void;<br>  shiftDown(): void;<br>}<br><br>class V8Engine implements Engine {<br>  start() {<br>    console.log(&#39;V8 engine started&#39;);<br>  }<br><br>  stop() {<br>    console.log(&#39;V8 engine stopped&#39;);<br>  }<br>}<br><br>class AutomaticTransmission implements Transmission {<br>  shiftUp() {<br>    console.log(&#39;Automatic transmission shifted up&#39;);<br>  }<br><br>  shiftDown() {<br>    console.log(&#39;Automatic transmission shifted down&#39;);<br>  }<br>}<br><br>// Define a CarFactory class that uses <br>// object composition to create more complex Car objects<br>class CarFactory {<br>  // Create an SUV object and <br>  // override its start and stop methods to include the behavior of a V8Engine<br>  // and AutomaticTransmission object<br>  createSUV(): Car {<br>    const suv: Car = new SUV();<br>    const engine: Engine = new V8Engine();<br>    const transmission: Transmission = new AutomaticTransmission();<br><br>    // Object composition: override the start and <br>    // stop methods of the SUV object to include the behavior <br>    // of the V8Engine and AutomaticTransmission objects<br>    suv.start = () =&gt; {<br>      engine.start();<br>      transmission.shiftUp();<br>      suv.start();<br>    };<br>    suv.stop = () =&gt; {<br>      transmission.shiftDown();<br>      engine.stop();<br>      suv.stop();<br>    };<br><br>    return suv;<br>  }<br><br>  // more factory methods<br>}<br><br>// Create a CarFactory object and use it to create SUV objects<br>const carFactory = new CarFactory();<br><br>const suv = carFactory.createSUV();<br>suv.start(); // Output: &quot;V8 engine started&quot;, &quot;Automatic transmission shifted up&quot;, &quot;SUV started&quot;<br>suv.stop(); // Output: &quot;Automatic transmission shifted down&quot;, &quot;V8 engine stopped&quot;, &quot;SUV stopped&quot;</pre><h4><strong>Advantages of the factory pattern include:</strong></h4><p><strong>Encapsulation:</strong> The factory pattern encapsulates the creation of objects, which can help hide the complexity of object creation from the rest of the codebase. It can improve the overall maintainability of the code.</p><p><strong>Abstraction:</strong> The code can work with the abstract type of an object instead of a concrete type. The Factory does not affect the rest of the codebase.</p><p><strong>Decoupling:</strong> The factory pattern helps decouple the creation of objects from the rest of the code, making the code more modular and easier to test.</p><p><strong>Code Reusability:</strong> Creating complex objects which can be reused in other parts of the code. This reduces code duplication and improves the codebase’s maintainability.</p><h4>Limitations of the Factory Pattern:</h4><p><strong>Complexity</strong>: Introducing additional complexity to the codebase, requiring adding classes and interfaces to define the object creation process.</p><p><strong>Dependency on the Factory:</strong> The Factory Pattern can create a dependency on the Factory class, making the codebase more tightly coupled.</p><p><strong>Limited flexibility:</strong> The Factory Pattern can be inflexible in certain situations, such as when the object creation process is highly variable or when many different types of objects need to be created.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=381e3955fbc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Decorator Pattern in Object-Oriented Programming]]></title>
            <link>https://robpaulblog.medium.com/understanding-the-decorator-pattern-in-object-oriented-programming-525a2cd69fad?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/525a2cd69fad</guid>
            <category><![CDATA[desing-pattern]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[object-oriented-design]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 09:24:02 GMT</pubDate>
            <atom:updated>2023-02-15T09:24:02.569Z</atom:updated>
            <content:encoded><![CDATA[<p>What is the Decorator Pattern?</p><p>The Decorator pattern is a design pattern in object-oriented programming that allows behaviour to be added to an individual object, either statically or dynamically, without affecting the behaviour of other objects in the same class. A decorator object wraps an object and adds new behaviour to it. The decorator object has the same interface as the original object so that clients can use the decorated object the same way as the original object. However, the decorator adds new functionality to the original object by modifying or extending its behaviour.<br>The Decorator pattern provides a way to add functionality to an object at runtime rather than compile time, and it is often used to add optional features to an existing class without modifying its source code. It also allows for a high degree of flexibility and customization since decorators can be combined and applied to create new and unique behaviour. Below is an example of a Coffee Decorator</p><pre>// Define the base component interface<br>interface Coffee {<br>  getCost(): number;<br>  getDescription(): string;<br>}<br><br>// Define a concrete component class<br>class HouseBlend implements Coffee {<br>  getCost() {<br>    return 1.50;   //encapsulation: the internal implementation of the cost calculation is hidden from other parts of the program.<br>  }<br><br>  getDescription() {<br>    return &quot;House Blend&quot;;<br>  }<br>}<br><br>// Define a decorator class<br>abstract class CoffeeDecorator implements Coffee {<br>  protected coffee: Coffee;<br><br>  constructor(coffee: Coffee) {<br>    this.coffee = coffee;<br>  }<br><br>  abstract getCost(): number;<br>  abstract getDescription(): string;<br>}<br><br>// Define a concrete decorator class<br>class Milk extends CoffeeDecorator {<br>  constructor(coffee: Coffee) {<br>    super(coffee);<br>  }<br><br>  getCost() {<br>    return this.coffee.getCost() + 0.50; //polymorphism : the cost method can be overridden by subclasses<br>  }<br><br>  getDescription() {<br>    return this.coffee.getDescription() + &quot;, Milk&quot;;<br>  }<br>}<br><br>class WhippedCoffeeDecorator extends Milk{ //inheritance: WhipCoffeeDecorator inherits from Milk<br>      constructor(coffee: Coffee) {<br>    super(coffee);<br>  }<br><br>  getCost() {<br>    return this.coffee.getCost() + 0.50;<br>  }<br><br>  getDescription() {<br>    return this.coffee.getDescription() + &quot;, WhipCoffeeDecorator&quot;;<br>  }<br>}<br><br>// Create a new House Blend object<br>let myCoffee: Coffee = new HouseBlend()<br><br>// Decorate the House Blend object dynamically with Milk<br>myCoffee = new Milk(myCoffee);<br><br>console.log(&quot;Cost: $&quot;, myCoffee.getCost());<br>console.log(&quot;Description: &quot;, myCoffee.getDescription())<br><br>myCoffee = new WhippedCoffeeDecorator(myCoffee)<br><br>console.log(&quot;Cost: $&quot;, myCoffee.getCost());<br>console.log(&quot;Description: &quot;, myCoffee.getDescription())</pre><p>The coffee Decorator is logically sound and easy to understand, but it has some limitations. The class could be overused, thinking if you want to add a decorator for every type of nut milk. You could overuse the decorators, and the complexity can be hard to manage; adding more decorators the more challenging to understand and maintain. Also, when an object has been decorated it can be difficult to remove or modify the decorators.</p><p>In general, the decorator pattern is a good choice when you need to add functionality to an object at runtime flexibly and modularly. Using decorators, you can create objects with different combinations of features without creating many subclasses and without modifying the original objects. However, it’s essential to consider the potential downsides of the pattern and use it with good judgement or having a sense that you will structure your code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=525a2cd69fad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Observer Pattern inTypescript]]></title>
            <link>https://robpaulblog.medium.com/the-observer-pattern-typescript-1a6c760614c8?source=rss-9daef450d58b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a6c760614c8</guid>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[desgin-patterns]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rob Paul]]></dc:creator>
            <pubDate>Wed, 01 Feb 2023 08:15:14 GMT</pubDate>
            <atom:updated>2023-02-01T13:15:13.698Z</atom:updated>
            <content:encoded><![CDATA[<p>The Observer Pattern in Typescript is a software design pattern where an object, known as the subject, maintains a list of its dependent objects (observers) and notifies them of any state changes.</p><p>In a nutshell, the Observer decouples senders and receivers.</p><p>What are the use cases for:</p><ol><li>User Interfaces: In the context of User Interfaces, there may be instances where multiple components require updates in response to changes in the state of another component.</li><li>Event Handling: In the context of Event Handling, there may be situations where multiple objects need to be informed upon the occurrence of an event, such as a button click.</li><li>Game Development: In the context of Game Development, there may be situations where multiple objects require notification of changes in the state of another object, such as changes to the score or game state.</li></ol><p>For example in the case of Social Media Applications, there may be instances where multiple users require notification of updates to a post or changes in its state.</p><pre>class Post {<br>    private subscribers: User[];<br>    private state: string;<br><br>    constructor(state: string) {<br>        this.subscribers = [];<br>        this.state = state;<br>    }<br><br>    subscribe(user: User) {<br>        this.subscribers.push(user);<br>    }<br><br>    setState(state: string) {<br>        this.state = state;<br>        this.notifySubscribers();<br>    }<br><br>    private notifySubscribers() {<br>        this.subscribers.forEach(user =&gt; user.notify(this));<br>    }<br>}<br><br>class User {<br>    name: string;<br><br>    constructor(name: string) {<br>        this.name = name;<br>    }<br><br>    notify(post: Post) {<br>        console.log(`User ${this.name} has been notified of a change to the post: ${post.state}`);<br>    }<br>}<br><br>const post = new Post(&quot;Initial state&quot;);<br>const user1 = new User(&quot;John&quot;);<br>const user2 = new User(&quot;Jane&quot;);<br><br>post.subscribe(user1);<br>post.subscribe(user2);<br><br>post.setState(&quot;Updated state&quot;);<br><br>// Output:<br>// User John has been notified of a change to the post: Updated state<br>// User Jane has been notified of a change to the post: Updated state</pre><p>The Post class acts as the subject in the pattern and maintains a list of subscribers in the subscribers array. The setState method updates the post’s state and notifies all subscribers through the notifySubscribers method. The User class represents an observer and has a notify method that outputs a message to the console when a user is notified of a change to a post.</p><p>The example also demonstrates the use of encapsulation, as the internal details of the Post class are hidden and only a public interface is exposed for other objects to interact with it. This ensures that changes to the internal details of the Post class do not affect other objects that depend on it.</p><p>A limitation of the Observer Pattern is that it can lead to an increase in the coupling between objects, which can make the system more complex and harder to maintain. Additionally, if an observer is no longer needed, it may be difficult to remove it from the subject’s list of subscribers, leading to potential memory leaks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a6c760614c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>