<?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 Kumar Pranaw on Medium]]></title>
        <description><![CDATA[Stories by Kumar Pranaw on Medium]]></description>
        <link>https://medium.com/@kumarpranaw?source=rss-e2e45dfa4136------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xg6XMdAXhlaF5qRim6eVnQ.jpeg</url>
            <title>Stories by Kumar Pranaw on Medium</title>
            <link>https://medium.com/@kumarpranaw?source=rss-e2e45dfa4136------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:46:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kumarpranaw/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[The MongoDB Aggregation Pipeline That Replaced 300 Lines of My Backend Code]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@kumarpranaw/the-mongodb-aggregation-pipeline-that-replaced-300-lines-of-my-backend-code-e7bda55c7094?source=rss-e2e45dfa4136------2"><img src="https://cdn-images-1.medium.com/max/1536/1*aco4LI0zl1EuwnEy2UrjsQ.png" width="1536"></a></p><p class="medium-feed-snippet">A story from 10 years of writing (and un-writing) database code</p><p class="medium-feed-link"><a href="https://medium.com/@kumarpranaw/the-mongodb-aggregation-pipeline-that-replaced-300-lines-of-my-backend-code-e7bda55c7094?source=rss-e2e45dfa4136------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@kumarpranaw/the-mongodb-aggregation-pipeline-that-replaced-300-lines-of-my-backend-code-e7bda55c7094?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7bda55c7094</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[mongodb-tutorial]]></category>
            <category><![CDATA[mongodbaggregation]]></category>
            <category><![CDATA[mongodb-atlas]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Tue, 04 Aug 2026 03:06:03 GMT</pubDate>
            <atom:updated>2026-08-04T03:06:03.520Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[MongoDB Aggregation Pipeline: A Complete Guide]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/mongodb-aggregation-pipeline-a-complete-guide-a4431b952472?source=rss-e2e45dfa4136------2"><img src="https://cdn-images-1.medium.com/max/1200/1*7KjVn_Rc6UEWDpStUymGIA.png" width="1200"></a></p><p class="medium-feed-snippet">MongoDB Aggregation Pipeline: A Complete Guide</p><p class="medium-feed-link"><a href="https://medium.com/swlh/mongodb-aggregation-pipeline-a-complete-guide-a4431b952472?source=rss-e2e45dfa4136------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/mongodb-aggregation-pipeline-a-complete-guide-a4431b952472?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4431b952472</guid>
            <category><![CDATA[analytics-database]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[aggregation-pipeline]]></category>
            <category><![CDATA[data-transformation]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Wed, 25 Jun 2025 08:10:24 GMT</pubDate>
            <atom:updated>2025-06-25T08:10:24.803Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Diving Deep into Angular Signals: A Comprehensive Guide (with RxJS Comparison)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Angular Signals, introduced in Angular v16, offer a refined approach to managing and reacting to data changes, leading to performance&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@kumarpranaw/diving-deep-into-angular-signals-a-comprehensive-guide-with-rxjs-comparison-a27c113795f6?source=rss-e2e45dfa4136------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@kumarpranaw/diving-deep-into-angular-signals-a-comprehensive-guide-with-rxjs-comparison-a27c113795f6?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/a27c113795f6</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-signals]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Fri, 31 Jan 2025 07:52:29 GMT</pubDate>
            <atom:updated>2025-01-31T07:52:29.758Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Unveiling Angular 17: A Comprehensive Guide to Latest Updates and Migration from Older Versions]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">In the dynamic realm of web development, Angular stands as a beacon of innovation, empowering developers to craft exceptional web&#x2026;</p><p class="medium-feed-link"><a href="https://blog.stackademic.com/unveiling-angular-17-a-comprehensive-guide-to-latest-updates-and-migration-from-older-versions-6c83bb481a34?source=rss-e2e45dfa4136------2">Continue reading on Stackademic »</a></p></div>]]></description>
            <link>https://blog.stackademic.com/unveiling-angular-17-a-comprehensive-guide-to-latest-updates-and-migration-from-older-versions-6c83bb481a34?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c83bb481a34</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-17]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Tue, 21 Nov 2023 15:31:18 GMT</pubDate>
            <atom:updated>2023-11-23T00:56:39.492Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Guide to Updating to Angular Version 16]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/a-comprehensive-guide-to-updating-to-angular-version-16-f782924a8d66?source=rss-e2e45dfa4136------2"><img src="https://cdn-images-1.medium.com/max/1400/1*LU-TxFL_XPrdsE6rR4lkCg.png" width="1400"></a></p><p class="medium-feed-snippet">Introduction.
Angular, the popular JavaScript framework, continues to evolve with new features and improvements. With the release of&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/swlh/a-comprehensive-guide-to-updating-to-angular-version-16-f782924a8d66?source=rss-e2e45dfa4136------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/a-comprehensive-guide-to-updating-to-angular-version-16-f782924a8d66?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/f782924a8d66</guid>
            <category><![CDATA[angular-migration]]></category>
            <category><![CDATA[angular-16]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 07:37:41 GMT</pubDate>
            <atom:updated>2023-10-15T11:01:51.577Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Custom Search Using Google API and C# .Net]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@kumarpranaw/custom-search-using-google-api-and-c-net-c3af10474f6b?source=rss-e2e45dfa4136------2"><img src="https://cdn-images-1.medium.com/max/1234/1*KIMWIX_UeB0N2HfZ8oHYVA.png" width="1234"></a></p><p class="medium-feed-snippet">In this article I am going to explain how can we scrape data using google custom search API in&#xA0;.net and export it into the csv.</p><p class="medium-feed-link"><a href="https://medium.com/@kumarpranaw/custom-search-using-google-api-and-c-net-c3af10474f6b?source=rss-e2e45dfa4136------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@kumarpranaw/custom-search-using-google-api-and-c-net-c3af10474f6b?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3af10474f6b</guid>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[winform]]></category>
            <category><![CDATA[custom-search]]></category>
            <category><![CDATA[wpf]]></category>
            <category><![CDATA[google-api]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Fri, 02 Oct 2020 18:37:20 GMT</pubDate>
            <atom:updated>2020-10-02T18:37:20.615Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[.Net Core Clean Architecture]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/net-core-clean-architecture-ec5c6c5574b?source=rss-e2e45dfa4136------2"><img src="https://cdn-images-1.medium.com/max/760/1*f0RVHfIoXd-RqxePGGGZWw.png" width="760"></a></p><p class="medium-feed-snippet">When we create a new project, It&#x2019;s always a challenge to design a clean and modular architecture. In this current blog I am going to&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/swlh/net-core-clean-architecture-ec5c6c5574b?source=rss-e2e45dfa4136------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/net-core-clean-architecture-ec5c6c5574b?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec5c6c5574b</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[mediator-pattern]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[dot-net-framework]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Wed, 29 Jan 2020 16:33:16 GMT</pubDate>
            <atom:updated>2020-01-29T16:33:16.501Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Factory Design Pattern (C#)]]></title>
            <link>https://blog.stackademic.com/factory-design-pattern-c-a330955b9ed6?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/a330955b9ed6</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Wed, 28 Nov 2018 06:55:13 GMT</pubDate>
            <atom:updated>2023-11-23T01:00:12.400Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will be going through another design pattern which is “Factory Design Pattern”. In my previous article, I discussed “What is design pattern?” and the types of design pattern and I also mentioned one of the types, which was a SOLID design principle, so let’s start</p><blockquote>What are We going To Learn ?</blockquote><p>In this article, we are going to learn the Factory Design Pattern step by step with examples.</p><p>And this also covers:</p><ol><li>Proper Factory Method</li><li>Inner factory</li><li>Abstract Factory</li></ol><blockquote>Defn:</blockquote><p>So in simple words, we can say that A factory is a component responsible for the wholesale (not piecewise) creation of objects.</p><p>Let’s talk about motivation to use “<strong>Factory Design Pattern</strong>”</p><ol><li>Object Creation logic becomes too convoluted.</li><li>The constructor is not descriptive</li></ol><p>There are lots of limitation like:</p><ol><li>The name of the constructor has to match the name of the containing type, so you cannot communicate additional information that how the object is constructed.</li><li>Cannot overload constructor with the same sets of arguments with different names</li><li>Object Creation (Non — piecewise, unlike Builder) can be outsourced to (A separate function( Factory Method)).</li><li>That may exist in a separate class (Factory)</li><li>Can create a hierarchy of factories with Abstract Factory</li></ol><p>One of the reasons why factories exist is because constructors are not that good, Let&#39;s take a look at the problem by taking a real example.</p><p>We are going to make a class named as the point which will represent the point x and y coordinates as field and make the constructor where we initialize the coordinates.</p><p>Now what happens after bit of a time we realize that we need to add polar coordinates also,so here comes the problem, now we can&#39;t be able to overload the same types in polar coordinates you can see in the screenshot we are getting the issue with red line, because as you can see that signature is exactly the same as the point above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6zjGxyo82h3f1He3HTkDyQ.png" /><figcaption>Issue While Overload Pic 1.1</figcaption></figure><p>so now the question is how to resolve this issue and the issue is how to initialize a point from both to cartesian coordinates as well as polar coordinates, so here we can start using enums named as Coordinates where we can define two types cartesian and Polar types, so now we end up doing additional arguments in constructor which specify the coordinate system and we as well give the default value as cartesian points.</p><p>Now we already have a couple of problems here, because we can no longer have the arguments as x &amp; y neither we can name them as “rho” and “theta” so we have to create some mutual named as a &amp; b please refer to the screenshot we changed the parameter name from x and y to a &amp;b we no longer need that as we don’t know in the runtime what coordinates point will going to be used</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dM9991gor9exQ_PThlGMSw.png" /><figcaption>Changed the signature with a and b, and by default, a coordinate is cartesian Pic 1.2</figcaption></figure><p>as in the case of the Cartesian system, it’s easy for the polar coordinates we added some formula. so here there is no indication of Cartesian coordinates or there is no clear specification which point is using from which coordinates.</p><p>So we have to add XML comments (refer to the screenshot pic 1.3) to let people understand how you are using a&amp;b parameters what basically are they. so that is a bit inconvenient, Still, we are bound to the name Point because constructor name should be matched to the class name, so we have the precise problem which can be resolved by the factory pattern,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V0yoyINSTrurNWq62fIRtg.png" /><figcaption>here are the XML comments to let the user know about parameters Pic 1.3</figcaption></figure><p>So getting rid of this issue we can use a much simpler way as we have two approaches to achieve this as I mentioned earlier so here we are going to use a proper factory for a first approach and also I will get rid of all the code which I wrote earlier, Here I am using Resharper tool which will help to refactor the code in very convenient way please have a look to the snapshot Pic 1.4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UDKacG-mAbz0psFb0xKfNQ.png" /><figcaption>In this image after selecting constructor press ctrl+shift+r then you will get a menu and then select “Replace Constructor with Factory Method” Pic 1.4</figcaption></figure><p>Notes: Those who don’t know about re-sharper it’s a tool which helps you to refactor your code as you want by less writing or you can use shortcuts for this you have to install ReSharper from its official site basically its a paid but still you can use it for a month with a trial</p><p>Link to Download: <a href="https://download-cf.jetbrains.com/resharper/ReSharperUltimate.2018.2.3/JetBrains.ReSharperUltimate.2018.2.3.exe">https://download-cf.jetbrains.com/resharper/ReSharperUltimate.2018.2.3/JetBrains.ReSharperUltimate.2018.2.3.exe</a></p><p>After Changing constructor to the factory, your code will be changed like this please refer to the snapshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1_r5K93QvUB8IRuKTmPIg.png" /><figcaption>This snapshot is for re-sharper after clicking on change option you will get this dialogue box where you can pass your name of the factory method Pic 1.5</figcaption></figure><p>So after clicking on next button, it will create one factory method of that constructor, so after creating we can have a look at the changed code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*syMEHXdPXb0lZ_uoNWBHkA.png" /><figcaption>Created the Factory method from the constructor Pic 1.6</figcaption></figure><p>Now compare the snapshot 1.6 to 1.1</p><p>So now when you will work with this points it will be much convenient to make a call and it will be easily understood that which points your calling lets have a look on the main method, refer to pic 1.7</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fHZQToCLaMiaXKHM6vFk6g.png" /><figcaption>Pic 1.7</figcaption></figure><p>So now here you can take a look while calling point it’s too easy to get which point you want to call and even you don&#39;t have to create the whole scenario which we tried doing first. So let’s check the output of CartesianPoint</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*csxrII800XFeFHd2xfNggQ.png" /><figcaption>Pic 1.8</figcaption></figure><p>So let’s talk about the advantages of the factory method</p><ol><li>You get to have an overload with the same sets of argument.</li><li>You can make Unique name to each method which is easy to understand</li></ol><p>so in above code everything is fine, and we had talked about separation so we will refactor this code more and as for now we are passing all factory methods in one place, so we can move it in a different class so I just made the small change in my code please refer to the screenshot Pic 1.9</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*7qYgMPvFHS9wU40mjRT9Gw.png" /><figcaption>Pic 1.9</figcaption></figure><p>In this, you can see we separated all the factory methods in a different class because separation is always a concern, as in my last article in Single responsibility principle I mentioned that, construction of an object is a separate responsibility, that what an object does. So instead of having the bunch of factories, we made one class named as point factory we moved all factory method in, Now when you will move all factory method to Point factory you might see an issue because our Point constructor is made private so just change it to the public, this is one of the challenges in c# you can not access any private members outside that class.</p><blockquote>Inner Factory</blockquote><p>However, we started using the factory method still we have a problem and that is constructor which we changed to private to public, so the goal in Inner factory method is the constructor should remain private and still we will be able to access the constructor. So the only way to make this possible is PointFctory Class will be made inside Point class. So instead of a point factory class on the top level, we will keep it in inside point class refer to the snapshot Pic 1.10</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vDdW_B3nLycdUpXPdedU_g.png" /><figcaption>Pic 1.10</figcaption></figure><p>In this pic, you can see that we had added PointFactory class inside the point class, and I had renamed the point factory class to factory class due to the naming convention as we know it’s already inside the point class so just changed it to factory now as you can see in the main method we are calling using, point.factory.newCartesian() so you can now access the private constructor of point class</p><blockquote>Abstract Factory</blockquote><p>So Why an “<strong>Abstract Factory</strong>” why can’t we just happy with the ordinary factory. In actual fact there only real use of the abstract factory is to give out the abstract object as a concrete object.</p><p>So let&#39;s create a setup to demonstrate the example of the Abstract Factory</p><p>Let’s Suppose we have a machine which makes a hot drink, which makes tea and coffee for example. but we want to give a user to give both to consume a drink without holding on to its actual types, so the user asks for the particular drink, they might say I want to have a cup of tea, but then we don&#39;t give them an object of type T instead we give them interface, so I am going to paste the code below which will demonstrate the Abstract Factory Method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*AyAbKEvsdlUIKu83cNpaaw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*zXdxomG6Ac-yOyPzEOqirw.png" /><figcaption>Pic 1.11</figcaption></figure><p>So idea here is not give object of type T, instead we give them interface, So we created IHotDrink in which we created Consume so client can consume any type of Hotdrink like tea or coffee as you can see in example I created two class Tea and Coffee and also made that as internal it’s not mandatory you can make it or not it’s totally up to you. and in both class we are consuming The Hotdrink, So here in example you can see is that no factory is going to return tea or coffee class they are going to return IHotdrink. So this is the basic idea to make it return Type of interface we are not returning any class, i had made this example bit complicated and you can check this complete example in GitHub. Here is the rest of the solution of Abstract Factory Method.</p><p>The rest of the functionality which i added here is</p><ol><li>Added Enums to decide what type of available drink we have.</li><li>Added How many amount of coffee or tea we want.</li><li>Added New Interface which will return a particular factory</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QbIEssH9DtfZnVJ6wCgaIA.png" /><figcaption>Pic 1.12</figcaption></figure><p>So I had made this example bit complicated you can use it in your own way it’s just a approach we followed with one example, but this example violates the rule of Open closed principle which we discussed in our last article, and the violation is we put enum here because let suppose we need to implement new hot-drink then we need to change in above functionality so that might be issue. so what we have to do is we have to get rid of enum approach and have to do with different way, so lets have a look in our new approach to achieve it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JXVJGcdxie0crz21IwL3xg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*ia9Hdyv9CDAwb86cCZHcow.png" /><figcaption>Pic 1.13 changed code of violation of OCP</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*MHkBaMJQ9nOSQI_VlyK3kQ.png" /><figcaption>Calling from Main method Pic 1.14</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8zQ9CRsfBQn41ac2Gssv7w.png" /><figcaption>Output Pic 1.16</figcaption></figure><p>So this is that how you achieve the Abstract Factory Method with not violating open-closed principle.</p><blockquote>Summary</blockquote><p>So lets try to summarize some of the thing which we used here, and learn about factories so far. So first of all we looked about factory method and that basically the idea to take your existing object and provide a static method. and that have some advantage from normal constructor which we seen on normal factory method. And of-course we can make a separate class who take care of the creation of particular object. We also looked about types of factories</p><p>Reference: Udemy course (By: <strong>Dmitri Nesteruk</strong>)</p><p>Find the Github Repo Here: <a href="https://github.com/pranavtechnossus/DeisgnPatternsC-/tree/master/FactoryPattern">Resources in Github</a></p><p>I hope this article will help you to understand bit about Factory pattern in case you are looking for resource i had provided the link of git-hub and clone that run and can see the differences by your own. Happy Coding !</p><p>Thank you!!</p><figure><a href="https://blog.usejournal.com/meet-journal-d222fce8db1d"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p><strong>This story is published in Noteworthy, where 10,000+ readers come every day to learn about the people &amp; ideas shaping the products we love.</strong></p><p><strong>Follow our publication to see more product &amp; design stories featured by the </strong><a href="https://usejournal.com/?/utm_source=usejournal.com&amp;utm_medium=blog&amp;utm_campaign=guest_post"><strong>Journal</strong></a><strong> team.</strong></p><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a330955b9ed6" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/factory-design-pattern-c-a330955b9ed6">Factory Design Pattern (C#)</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[.Net Design Pattern]]></title>
            <link>https://medium.com/@kumarpranaw/net-design-pattern-3b747d155588?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b747d155588</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Fri, 17 Aug 2018 21:32:27 GMT</pubDate>
            <atom:updated>2019-01-28T20:36:35.122Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oVIBAkUCg1tcAKoYfqXd_A.png" /><figcaption>SOLID Design Pattern</figcaption></figure><blockquote><strong>Why Design Patterns ?</strong></blockquote><p>Before talking about design patterns let’s talk about myth which we all have while implementing design patterns</p><p>Myth 1:- All design patterns must implement in a project that makes a good architecture.</p><p>Fact:- There are no restrictions to implement any architecture its just come naturally its all up to the demand of the project, so the fact is patterns come up naturally, they are completely on demand as per the scenario.</p><blockquote><strong>What is design pattern?</strong></blockquote><p>In software engineering, a <strong>design pattern</strong> is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn’t a finished design that can be transformed directly into code.</p><p><em>(taken from : Wikipedia)</em></p><p>So, basically we can say that design pattern is at code level, at the pseudo-code level than it becomes a design pattern.</p><p>Design patterns are common architectural approaches, popularized by the Gang of Four book(1994). The notion of design patterns has been translated to just about every object-oriented programming languages that’s out there like C#, Java, Ruby and lots of other languages, even languages which are not properly object oriented like Java script. In c# they actually made design patterns, and in addition some of the design patterns are now available as libraries so you can download the library, and that library actually gives you a design pattern implementation</p><blockquote><strong>What are We going To Learn</strong></blockquote><p>In this article we are going to learn SOLID design pattern principles step by step with examples</p><p>SOLID design Principles</p><ol><li>S : Single Responsibility Principle (S.R.P).</li><li>O : Open-closed Principle (O.C.P).</li><li>L : Liskov Substitution Principle (L.S.P).</li><li>I : Interface Segregation Principle (I.S.P).</li><li>D : Dependency Inversion Principle (D.I.P).</li></ol><blockquote><strong><em>S</em>ingle Responsibility Principle</strong></blockquote><p>Single responsibility principle is that a typical class is responsible for one thing and has one reason to change. The single responsibility principle its a just piece of very good advice on how to build systems. And it specifies that any particular class should have just a single reason to change.</p><p>So let’s understand it with an example.</p><p>Let’s suppose you want to make a journal where you write down your thoughts, so you make a classical journal.</p><p>so we will make a class of journal and we will have bunch of properties in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*rYmAfsv56nR230mvGbFcLw.png" /><figcaption>Pic 1.1</figcaption></figure><p>So here you can see that in class journal we have some sort of properties like list of string type and some methods for adding entry and removing entry as well whereas adding entry takes an string as parameter to add entries and removing entry takes a parameter index which is integer type to remove the particular entry from that index. what we are going to do now is override two string and join all the entries with a line you can see in the image last method, so here i had created my journal now what we are gonna do we will add bunch of entries</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*BDHznPre7p7YRxKdNnJLqg.png" /><figcaption>Here we are adding bunch of entries in my journal</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*j-p9t-4gdzxDG9JxzCoZPw.png" /><figcaption>And yes here is my journal which i had added</figcaption></figure><p>Now here you can see all the methods inside journal actually relate to the journal, so we are adding entries to the journal, removing entries from the journal, and in addition we’re kind of printing them to the command line.</p><p>Now let’s suppose that you also want to persist the journey though you might want to save that journals into a file, so typically the kind of things people might do is actually start making methods right here so lets have a look on that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*PjIHMo0BckBb5iEyhbb8Tg.png" /><figcaption>Added more methods in journal class</figcaption></figure><p>Now the problem here and the reason why we are violating the Single Responsibility Principle is that, we are adding to much responsibility to the Journal class as you can see in the snapshot. You can also see that the journal is now responsible not only for keeping entries but also managing all of the above persistence or newly added functionality in the same class. And this is something that the single irresponsibility kind of mentality should hopefully get you not do. So the idea here is that instead of doing this what you would typically do is you’d make a new class which handles the persistence of things lets see in example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*MMUnRF8b5tyW1rCNTOBPqQ.png" /><figcaption>New class with single responsibility for handling journal to file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*GMOwCixLhPtgISVEOVkNag.png" /></figure><p>So here you can see that journal class is concerned for keeping a bunch of entries and the persistence class is concerned with saving whatever object that’s being fed whether it’s a journal or something else to a file.</p><p>So the whole Point of the Single Responsibility Principle is that a typical class is responsible for one thing and has one reason to change</p><blockquote><strong>Open-Closed Principle</strong></blockquote><p>Open closed principle states that classes should be open for extension</p><p>Let’s Understand it with an example, First of all i am going to violate open closed principle and then we’re going to rectify this and get the implementation which actually doesn&#39;t break open close, Now let’s suppose we’re building a ordering system may be e-commerce type where we can buy products and the products have certain categories and certain traits so let’s create that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*9MENI_bLy4LtSH5fGQn76g.png" /><figcaption>so here we created enums for products Size and color</figcaption></figure><p>Now let’s suppose you want to filter some products, so instead of using linq to filter out a collection of products we’re having to restrict ourselves to only filtering by certain criteria, so we’re going to restrict the kind of filtering that you can do by using a product filter, so let’s suppose our visitors on website want to filter the product by size so implement a method</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*kUE98ccHD8UYeRGE2riKrA.png" /><figcaption>fig 1.2 Implementation of filterbySize method in Product class</figcaption></figure><p>Now lets add some products and filter it by size</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*7Fti2_DwSkwL5mMNQ2grDA.png" /><figcaption>Adding products and filtering it by size</figcaption></figure><p>But you all notice that so far we don’t have any filtering by color we only have filtering by size in (fig 1.2) which isn’t what we want, so in order to implement this new functionality we unfortunately have to go back into the filter and we have to modify filter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*bpYMldd6kxLujwV7ku0pfQ.png" /><figcaption>here you can see both filter has been added.</figcaption></figure><p>now lets execute and see what we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*JYMcPSJ7YrsAvjVEjq35Ew.png" /><figcaption>we added some products and filtered it by our method</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*wyIBwRLBX-oCXAzWPk2qUg.png" /><figcaption>Output of Large and green products</figcaption></figure><p>Now we are getting our output as expected, now unfortunately what happens you want filter by both sides and call it, You’re going to let people specify both the size and the column you want to, so this is a bit of problem because now we once again have to open up product filter and add yet another piece of functionality, and this whole thing which i show completely violates open-closed principle, because the open closed principle states that classes should be open for extension, which means it should be possible to extend the product filter class and it should be possible to make new filters but they should be closed for modification which means nobody should be going to the back into the filter and actually editing the code which is already there because we can assume that filter might have been shipped to a customer, Now here question raises that how can we extend things without actually going back and changing their bodies, yes it’s Inheritance, and the actual answer is that you can implement interfaces thereby extending the capabilities of the system, so instead of having some rigid functionality we are going to make some interfaces, And the first interface that we are going to make is going to be called specification which basically dictates whether or not a product satisfies some particular criteria</p><p>Now other side of the puzzle is another interface and this one is going to be called an IFilter, So we take a bunch of items type T and lifter according to the specification which is defined here, So the interface is that you return an Ienumerable of T and you basically filter a bunch of Ieneumerable of the items given the appropriate specification given specification</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*rJOZsVBKkqQ2iQOqm7ns7g.png" /><figcaption>creating All types of specifications to filtering products</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*xTtKfcQZqqxqM9W8RXTbOw.png" /><figcaption>And specification</figcaption></figure><p>So the idea of creating AndSpecification will actually take two specifications like a colorSpecification and sizeSpecification and it will and them together</p><p>now lets run it and see the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*58nUNyU9fNblmifIGNjpyQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*tw4uVaq786NsXGRe_ZyX9Q.png" /><figcaption>Output</figcaption></figure><p>So this has been a demonstration of the open closed principle, lets recap all what we did in this principle O.C.P states that parts of the system or in the subsystem have to be open for extensions so you should be able to extend the functionality of a filter for example but they should be closed for modification, so we shouldn’t have to go back into better filter for example and start adding things right here, you shouldn’t be able to do that</p><blockquote><strong>Liskov Substitution Principle</strong></blockquote><p>L.S.P named after Barbara Liskov, so the idea here is quiet simple that you should be able to substitute a base type for a sub-type, let’s understand with an example:</p><p>so let’s suppose we have a class of rectangle, having some property in it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*K9TuYpMeaKtwIMRfBh68Ug.png" /></figure><p>so let’s go ahead and perform some operation on a rectangle, for ex: calculating the area</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*_vqv9zJDaVkgNVRxoVYK7g.png" /><figcaption>calculating an area</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*uMj8lHpd-qZhdREDezfVwA.png" /><figcaption>output</figcaption></figure><p>Now this is fine until we decide to also implement a square class and we decide to inherit square form rectangle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*6uRRbAKKhpi-HvwgR9dADw.png" /></figure><p>Now we are inheriting the square from rectangle and then we decided to handle the assignments to the width and height because the square has to be consistently a square</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*h2fueXDKuB2z2NIhmN02rg.png" /><figcaption>Fig. Square 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*cSulx70SPUBxNx6tFTePrw.png" /><figcaption>Fig. Square 2</figcaption></figure><p>Now here i will be discussing directly why i am using this principle rather than putting the code which violates L.S.P</p><p>so the idea here basically is if you have a square than it’s perfectly legal for you to store a reference to a square as a rectangle variable, as you can refer through the snapshot we are using reference of rectangle, because remember inheritance basically a square is a rectangle, so we should be able to legally change Square to rectangle for reference you can see the snapshot, according to that nothing should change, but no it might won’t work because when we are setting the width than we are only setting the width we are not setting the height</p><p>So L.S.P basically says that you should always be able to sort of upcast to a base type and the operation should be still OK, means that this quiz should still behave as a square even when your’e getting reference to a rectangle. So lets fix this issue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*ntszmPxnxw-7ALaFy2UYXQ.png" /></figure><p>So what we did here is we’ve used new keyword but instead of that what we could do is make each property virtual and then of-course instead of new we would override and this would work properly</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*P3jMY1KE9M5Lkju6prktpw.png" /><figcaption>Output</figcaption></figure><p>and yes it’s working properly, what happens is even though we are holding a rectangle reference to a square when we go and access the width what really happens is a walk over the virtual function table because it’s looking at width and so it’s find the appropriate setter and calls the appropriate setter in fact on the square.</p><blockquote><strong>Interface Segregation Principle</strong></blockquote><p>The Interface Segregation Principle states “that clients should not be forced to implement interfaces they don’t use. Instead of one fat interface many small interfaces are preferred based on groups of methods, each one serving one sub module. Basically I.S.P is something that you’re likely to encounter in the real world, where you just building interfaces which are too large and the idea is quite simple that your interfaces should be segregated so that nobody who implements your interface has to implement functions which they don’t actually need, So let’s understand it with an example</p><p>Let’s suppose you have a document and you want to do different things with the documents so you try to emulate some sort of printer or scanner, But there is also this thing called the multi-function printer which does both the printing scanning. So you decide oh i’ll make an interface for everything so you build one big interface called “IMachine” and this IMachine interface does all things, so it can print the document, it can also scan the document and you can fax the document as well, SO you build this kind of interface which is just fine so long as you work with multi functional printer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*LinjhcINNGP_OowXzJw2lg.png" /><figcaption>IMachine Interface</figcaption></figure><p>So this is OK but when you go ahead and you decide to make just a good old fashioned printer it cannot scan and cannot fax any documents anything like that, so the problem is that you’ve only got this one big interface with lost of responsibility attached to it, so what we do we have to implement this interface to our old fashioned printer class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*oKO_Urmpc2HWLLFgMxJ37w.png" /><figcaption>Old fashioned printer implementing IMachine interface</figcaption></figure><p>so now here the question is what you do about the scanning and faxing method, for printing we will add functionality for print method, so what we can do for rest method either we can throw some exceptions or we can put some messages that this operation is not supported or something like that, so that’s a bit of a problem here. And that is where the Interface segregation principle comes in. So the idea is to make sure that people don’t pay for things they don’t need, So instead of having one bug interface you should have lot’s of smaller interface which are more atomic or we can say in the sense that they cover a particular concern,</p><p>Let’s make a “IPrinter” interface where you would have the print function and similarly for the scanning</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*kqlYjRXvrH7ejOHlRQ0iRQ.png" /><figcaption>Something like this</figcaption></figure><p>So if you want make photocopier function then you might want to have the Iprinter and Iscanner interface class and it’s implementation in that class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*p8dBgxlvJWBzukxsnmUqtA.png" /></figure><p>Or of-course if you do want a higher level interface as well like kind of “IMultifunction” interface, you can have it as well because interface can inhertit from interfaces so you can have an “IMultifuncitonDevice” which is actually inheriting both “IScanner and IPrinter”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*BSOD95sHuyBhs2XclfjaKQ.png" /></figure><p>just for make sure that you have different options to doing it, so one way would be if you have a class called multifunction machine of some kind you can just go ahead and you can implement this “IMultifunctionDevice” interface, thats one approach,So lets see what we going to do here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZuCQN-0wfOo8T6Y6JSiSxA.png" /></figure><p>so what we did here we created a class which is implementing “IMultifunctionDevice” and let’s suppose we already have implementation of “IPrinter and IScanner” which is Inherited by “IMultifunctionDevice” an now what we can do is we can delegate the calls to each of the interface methods of “IMultifunctionDevice”, now we are actually delegating the calls to the calls of a inner printer and scanner variables, So here is one classic example of decorator pattern .</p><p>So this is the “Interface Segregation Principle”, A basic idea that if you have an interface which include too much stuff then just break it up it apart into smaller interface.</p><blockquote><strong>Dependency Inversion Principle</strong></blockquote><p>D.I.P is very simple and it states that high level parts of the system should not depend on low level parts of the system directly that instead they should depend on some kind of abstraction.</p><p>So what’s it like to have high level and low level parts of the system, so we are going to look at a scenario right now, we are going to find some relationship between some people,</p><p>First of all we may as well define certain relationships a relationship between two people like for example you can be a parent or child and we will be making this as enum</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*L2ie6pKIPWgg7r3p_cJ7XQ.png" /></figure><p>and now we can define person</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*Nq97pR0IZfAyN_f9_z-uQw.png" /></figure><p>and I’m going to put person class in a class called relationship so and here we are just going to have a flat list of relations between different people, so i’ll have a private list and I’ll use those seven couples here so I’ll have the person from which , So we will have a private list and we will be using c#(7) Tuple here, we’ll have the person from which the relationship stems the relationship itself and the person which the relationship applies and we will initialize it with a new list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yP4mi9Tl_cD-DhLwDGWAGQ.png" /></figure><p>so this is a set of low level and what we can do then on the low level is we we’re going to define some sort of API for actually adding a parent and child relationship, So we are going to do very crudely , ADD parent and child and here i will have the person parent and the person child and know just duplicate the data not something that you do in typical database but something that is very popular in today’s design when you just duplicate data for the purpose of speed of access</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eGj8FF3219VpLC8McCrjhg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fzGFQeOcB0tE8gzWhuwttw.png" /><figcaption>Setting up in main method</figcaption></figure><p>ok so this is our low level API an now question is well how do we actually perform research on it one to find out all the children of a particular person so in research class we have a main method we are adding some person, so here john has two children and we can define the low level relationships module to come and pass this information so we present this information we save our relationships,</p><p>Now we actually want to take the low level module and we want to somehow access it in a high level research module, so one of the way not a best way we can say is to simply allow the high level of the research module access to some of the internals of the low level module by giving it the list of relations so you can do something, if we make a constructor for research which actually takes relationship as the argument, so now what we wan to do is to access all the relationship so how can we do it, one of the way is we simply expose this private field as as public property and that’s pretty simple you can see in the above snapshot highlighted with red box, and what we can now do is we can perform some sort of research by accessing this low level interface</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*fbq6_vxO7tdXjrwMOq1pAA.png" /><figcaption>so this is a workable scenario</figcaption></figure><p>so lets execute this and see the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*aCBegF2fnie786I0FzaBxA.png" /><figcaption>And yes we got the expected result</figcaption></figure><p>So now the problem with this scenario and the reason why the dependency inversion principle exists is that’s we’re accessing a very low level part of the relationship class we’re accessing its data-store and we’re accessing it through specifically designed property which exposes the private thing has public and what this means in practice is that relationships cannot change it’s mind about how to store the relationships.</p><p>So a better way which would allow relationships to change is to provide a form of abstraction based simply defining an interface</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*q_Xx2tIVfsoZWNiFZzjGOw.png" /></figure><p>and now we are going to implement that interface into relationships so we will be removing all extra code which is marked as red and also we no more need constructor in that research class so what we did now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dR0xTLb_bCjKtf-w3nRyhA.png" /></figure><p>so we now have a low level module but instead of depending on this low level module we depend on an abstraction which is the relationship browser so what we can do in our research module which is the high level we can build another constructor</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*zOcD6gn46tnbR5KFn3ozHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*xYMc0hqFdhbnMiWu7Xzn1g.png" /></figure><p>and ofcourse i get the same output without depending on the low level implementation we have.</p><p>So now what happens is relationships can actually go ahead and change the way that it stores the relationships it can change the underlying data structure because it’s never exposed to the high level modules which are actually consuming it.</p><p>So what We learnt</p><ol><li>When to use this principles and when not</li><li>What are the benefits of using these principles</li><li>All principles of SOLID design pattern with Examples</li><li>What is design Pattern</li></ol><p>Reference: Udemy course (By: <strong>Dmitri Nesteruk</strong>)</p><p>Find the Github Repo Here: <a href="https://github.com/pranavtechnossus/DeisgnPatternsC-/tree/master/SolidPrinciples">Resources in Github</a></p><p>I hope this article will help you to understand bit about SOLID design pattern in case you are looking for resource i had provided the link of git-hub and clone that run and can see the differences by your own. Happy Coding !</p><p>Thank you!!</p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_read_later_text">Journal</a>.</p><p>🗞 Wake up every Sunday morning to the week’s most noteworthy Tech stories, opinions, and news waiting in your inbox: <a href="https://usejournal.com/newsletter/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text">Get the noteworthy newsletter &gt;</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b747d155588" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Internationalization(Angular & i18n)]]></title>
            <link>https://blog.stackademic.com/angular-internationalization-angular-i18n-79f98f1da6ed?source=rss-e2e45dfa4136------2</link>
            <guid isPermaLink="false">https://medium.com/p/79f98f1da6ed</guid>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[multilingualism]]></category>
            <category><![CDATA[angular-5]]></category>
            <category><![CDATA[angular-6]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kumar Pranaw]]></dc:creator>
            <pubDate>Tue, 17 Jul 2018 10:29:16 GMT</pubDate>
            <atom:updated>2023-11-23T01:00:41.807Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*tIq3I93HnoU43hiHqXoj2Q.jpeg" /><figcaption>i18n( Internationalization &amp; Localization)</figcaption></figure><p><strong>What is Internationalization?</strong></p><p><em>Internationalization (i18n) is the process of developing products in such a way that they can be localized for languages and cultures easily. Localization (l10n), is the process of adapting applications and text to enable their usability in a particular cultural or linguistic market. For application developers, internationalizing an application means abstracting all of the strings and other locale-specific bits (such as date or currency formats) out of the application.</em></p><p><strong>What it means to actually internationalize ?</strong></p><p><em>It’s a lot more than just taking translations, which is the common misconception, all we know what to do is it’s translate your app from English to french, English to Spanish and you are done. It’s lot than just modifying your application from client side</em></p><h4>Lets set an Agenda what we are going to continue with.</h4><ol><li><em>What are i18n &amp; L10n?</em></li><li>Why is multilingual support so important?</li><li>Getting a user’s locale</li><li>Practical Implementation of <strong>i189 in Angular 5 </strong>step by step.( <a href="https://github.com/pranavtechnossus/angular-internationalization/tree/master/multilingual-app">Link to the git hub source</a> )</li><li><strong>What are i18n &amp; L10n?</strong></li></ol><blockquote><strong><em>i18n </em></strong><em>(short form of internationalization) is the process of designing a software application so that it can potentially be adapted to various languages and regions without any changes in engineering and if we talk about what </em><strong><em>L10n </em></strong><em>(short form of localization) is the process of adapting internationalized software or a specific region or language by adding locale-specific components and translating text</em></blockquote><p><em>(taken form: Wikipedia)</em></p><p>Notes: <em>why internationalization called as i18n let me break it through so you can understand easily, in internationalization word after </em><strong><em>i</em></strong><em> there is 18 text to count you can count as well and the last text is </em><strong><em>’n’ </em></strong><em>so it’s simply called [</em><strong><em>i+18(text </em></strong><em>count</em><strong><em>)+n</em></strong><em> ] and same is localization [</em><strong><em>l+10(text count)+n</em></strong><em>](for example; my name is </em><strong><em>pranav </em></strong><em>so it will called ‘</em><strong><em>p4v</em></strong><em>’ in that way means first and last letters remain same and the number is the count of between first and last letters. it’s called as </em><strong><em>Numeronym</em></strong></p><p>2. <strong>Why is multilingual support so important?</strong></p><p><em>so now let’s talk about why multilingual is more and more important nowadays. So if you talk to people in the industry, people are talking and thinks like global forums. They will tell you that the next billion users off the internet don’t speak English or are uncomfortable with using English as a primary language of communication.</em></p><p><em>So here the Question comes. is English Still the Language of the Internet?</em></p><ol><li><em>English is no longer the language of the web( do think about that.)</em></li><li><em>Chinese internet users to overtake English language users by 2015</em></li><li><em>Another one that talks about the new internet, the one that’s for the next 2 billion users, that are outside of developed nations.</em></li></ol><p><strong>3. Getting a user’s Locale</strong></p><p><em>Unfortunately, there is no 100% reliable way in the browser of getting the user’s locale information-unless you ask the user explicitly ( </em><a href="https://medium.com/u/4b6c154e184f"><em>Marcos Caceres</em></a><em>marcosc )</em></p><p>4.<strong> Lets Dive in to the code and see how it works</strong></p><p><strong>1st Step:</strong></p><blockquote><em>Create your angular project i did with </em><strong><em>cli </em></strong><em>you can create </em><strong><em>manually </em></strong><em>doesn’t matter</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*U0RuIuXLhosAkvXzTEHpbA.png" /><figcaption>I created the project named “multilingual-app”</figcaption></figure><p><strong>2nd Step:</strong></p><blockquote>I added Bootstrap package to look html bit fancy it’s not necessary you can continue without that</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0M0K3TXAqGFRrLLzvEZKQA.png" /><figcaption>Added using cli version 3.3.7,( add the path of bootstrap to angular.json file to start using it)</figcaption></figure><p><strong>3rd Step:</strong></p><p><em>Now we are going to use angular i18n attribute with a custom id, means every translation generated by i18n tool will be easily readable and easy to maintain. I am not adding description here but while adding description its easy to improve the accuracy of translation.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9JfTkh3yf11Ti3Y6dmLERQ.png" /></figure><p><em>Great! In the code above we added id to our app.component template. which will be easy to convert from source language to target language, will see in the next steps. this id will generate source tag in “</em><strong><em>messages.xlf</em></strong><em> “ for each where you have mentioned @@id so that will be really easy to add target</em></p><p><strong>4th Step:</strong></p><blockquote><em>Now we are going to run the command “ng xi18n” from angular cli to generate the main translation file.This file is going to generate our base translation file called “messages.xlf” in our src folder (you can pass another location or/and name as params to the command).</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mfrba16lE5N-cPIGfWeZCg.png" /><figcaption>Here is my generated file check the same file of yours.</figcaption></figure><p><strong>4th Step:</strong></p><p><em>As now we have our main translation file we have to create the new language specific translation files. First, we are going to create a folder “locale” under our src folder, where is our language specific files are going to live.</em></p><p><em>Now copy the generated file into locale folder and rename it to “messages.es.xlf” </em><strong><em>(</em></strong><em>as you can see i renamed </em><strong><em>messages.xlf</em></strong><em> to </em><strong><em>messages .es.xlf</em></strong><em> because i wanted it to convert to Spanish you can use “fr” for french and “zh” for Chinese and there are lots of we will configure in later steps</em><strong><em>)</em></strong><em> currently i am doing it for only one language translation for </em><strong><em>Spanish .</em></strong></p><p><strong>5th Step:</strong></p><p><em>This step is to edit this new file with the spanish translatio, in most of the application company hire a translator that is one who providing the translated version of the file, but in my example i am using google translator for translating the source file to target file you can find it in attached snapshot. we are going to do it ourselves.To do this we need to add a &lt;target&gt; tag after each of the &lt;source&gt; tags in the file. Then we type the spanish version of the text in the target tag.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BDLfluWW6bpn-ryDYdOrAA.png" /><figcaption>This is before adding target tag (*source will be generated automatically once you run the code which i mentioned in earlier step “<em>ng xi18n”</em>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GUY56MSPvMosQt4p646euQ.png" /><figcaption>here you can find i had added the target manually.</figcaption></figure><p><strong>6th Step:</strong></p><p><em>Now we are done with the coding part let’s do some configuration so we will be able to run this file in the language we added to.</em></p><p>in angular.json go to the configuration and change the line as shown in snapshot or add it if not there</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fS_f6zRu6xCsvjqQX_argw.png" /><figcaption>its inside Serve add the language which you are creating for kindly notice here i had provided “es” because i am translating app in Spanish i already told you what you have to do if you want to go through different language</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*hZprDldNOuEgxea48K7KTg.png" /><figcaption>add these lines inside configuration area and also again keep in mind don;t forget to change the language if you are using different language which i am not using</figcaption></figure><p><em>after configuring all these steps now you are ready to run your application successfully so let’s run it</em></p><p><em>by using the command: ng serve — — configuration=es</em></p><p><em>you can run you app which is in English same as you do( ng serve) you just have to change for when you are trying to change language</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KfXXU8vhLXI39kzQo3yTqQ.png" /><figcaption>Again don’t forget to change the language here which is the common mistake which we do</figcaption></figure><p><strong>Now lets see the Difference (Output):</strong></p><p><strong>Before Translating The app</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DWx9kd_XtbMUVvxt2yHlLg.png" /></figure><p><strong>After Translating the app</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0KiE5gkdgrRq0gCtxEiHQ.png" /></figure><p>yippee!! We successfully made it</p><h4>Great! Let’s have a look what we did so far</h4><ol><li>We created an Angular project</li><li>We configured Angular to compile with different locale.</li><li>we used attribute i18n to provide angular with the information that is needed for translation</li><li>we ran a command which generated a base file for source translation. I mean base file which is created inside source</li><li>Create language-specific files inside the locale folder (you can choose your own language I choose Spanish)</li><li>Configure angular to be able to compile the proper language-specific file.</li><li>We configured how to serve the correct application package.</li></ol><p>I hope this article will help you to understand bit about internationalization in case you are looking for resource I had provided the link of git-hub and clone that run and can see the differences by your own. Happy Coding!</p><p>GitHub Repository <a href="https://github.com/pranavtechnossus/angular-internationalization/tree/master/multilingual-app">Find here</a>.</p><h4>More where this came from</h4><p>This story is published in <a href="http://blog.usejournal.com/">Noteworthy</a>, where thousands come every day to learn about the people &amp; ideas shaping the products we love.</p><p>Follow our publication to see more product &amp; design stories featured by the <a href="https://usejournal.com/?utm_source=usejournal.com&amp;utm_medium=blog&amp;utm_campaign=guest_post">Journal</a> team.</p><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79f98f1da6ed" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/angular-internationalization-angular-i18n-79f98f1da6ed">Angular Internationalization(Angular &amp; i18n)</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>