<?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 Cindy on Medium]]></title>
        <description><![CDATA[Stories by Cindy on Medium]]></description>
        <link>https://medium.com/@cchen.co?source=rss-1b8a8ad37737------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*T9Etk_EvJpDyKO1wRvuAeA.png</url>
            <title>Stories by Cindy on Medium</title>
            <link>https://medium.com/@cchen.co?source=rss-1b8a8ad37737------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 21:00:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cchen.co/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[Abstract Factory Pattern<Design Pattern Series>]]></title>
            <link>https://medium.com/@cchen.co/abstract-factory-pattern-design-pattern-series-32579472df69?source=rss-1b8a8ad37737------2</link>
            <guid isPermaLink="false">https://medium.com/p/32579472df69</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Cindy]]></dc:creator>
            <pubDate>Thu, 10 Sep 2020 10:11:39 GMT</pubDate>
            <atom:updated>2020-09-17T04:25:50.049Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*KbWYRjwSiSfD_jud" /><figcaption>Photo by <a href="https://unsplash.com/@jstrippa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">James Harrison</a> on <a href="https://unsplash.com/s/photos/mac-programming?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><strong><em>Writer’s Note: </em></strong><em>If you’re first time here, it’s a series about all the important design patterns that you should know. Take a sip 🥃 Let’s dig in!</em></p><p>Today we’re talking about one of the creational patterns: <strong>Abstract Factory Pattern</strong>.</p><blockquote><em>Before getting to know Abstract Factory Pattern, there’s actually another quite alike but simpler pattern called: Simple Factory Pattern. </em><a href="https://medium.com/@cchen.co/simple-factory-pattern-design-pattern-series-2f8a35093567"><em>Go check this Simple Factory Pattern out firs</em></a><em>t and we’ll meet you back here.</em></blockquote><p>Here’s a UML of Abstract Factory Pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JE3SJWXXJz-DPEJfiWku9g.png" /><figcaption>Abstract Factory Pattern UML</figcaption></figure><p>I know there’s quite a lot to take in.</p><p>First, let’s figure out how Abstract Factory Pattern helps us. 😻</p><h3>Why do we use Abstract Factory Pattern❓</h3><p><strong>Abstract Factory Pattern </strong>is a one of the creational design patterns.</p><p>It provides an interface for a family of products. It becomes useful when you don’t know which product will be added into the family beforehand.</p><ol><li><strong>Compatible Products:</strong> Products that created from the factory are 100% compatible with each other.</li><li><strong>Decrease Coupling: </strong>Concrete products’ creation are now separate from client.</li><li><strong>Single responsibility: </strong>Product creation is now in each subclass.</li><li><strong>Easy to extend:</strong> Just add another set of product family and it wouldn’t affect any current codes</li></ol><h3>How to do it❓</h3><p>Remember our garment factory, <strong>Wonderful Shape Clothe Factory</strong>, from the Simple Factory Pattern? 🧐 <br>Except from leather jackets and hoodies, Wonderful Shape Clothe Factory now sells more products.</p><p>There are several product lines such as the Yoga Product Lines, Work Outfit Product lines and so on…</p><blockquote>Our Goal: People can order a package of a certain product line and ready to go!</blockquote><h4><strong>1. Create Interface For Products</strong></h4><p>First, let’s create some products for Wonderful Clothe Factory.<br>As a factory, we definitely need all kinds of pants and shirts. So here’s two interface for Pant and for Shirt.<br><strong>🚩 &lt;interface&gt;Pant<br>🚩 &lt;interface&gt;Shirt</strong></p><h4>2. Create Concrete Products For Each Abstract Product Interface</h4><p>Since we have two interface for Pant and Shirt, it’s time to make some real, concrete products!<br>Remember our goal is to create a package of products for people to choose.<strong><br></strong> <strong>🚩 Formal Pants + Formal Shirt<br>🚩 Yoga Pants + Yoga Shirt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*qjy34L26Ai5VydTnt2IAJQ.png" /><figcaption>Products’ UML</figcaption></figure><h4>3. Create Concrete Factory For Each Product Line</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uQDf01SHs_I8njEnaohtCw.png" /></figure><p>So we create a Yoga Clothe Factory for Yoga Pants and Yoga Shirts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6MjPRS80ol5EM2orlFor3Q.png" /></figure><p>We also create a Formal Clothe Factory for Formal Pants and Formal Shirts.</p><p>Both of the concrete factories have the same methods: createShirts() &amp; createPants()</p><h4>4. Create Interface For Factories</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*gwJzFcQISiqWjjMjPvP-bA.png" /></figure><p>We create a <strong>Clothes Factory</strong> which has the createShirts() &amp; createPants() methods.</p><p>And both of these methods return <strong>abstract Product</strong>!</p><p>Our clients don’t really care about which style they’re wearing.</p><blockquote>As long as the shirt goes well with the pants, everything is good!</blockquote><h4>5. Create Client</h4><p>Our clients are those people who want to get dress as quick as possible. So what kind of style they’re wearing today, they don’t really care!</p><p>Just give them a package with a shirt goes well with a pant!<br>That’s why our client only have to know the factory is an abstract clothe factory. On Monday, client’s clothe factory could be a Yoga Clothes Factory and on the other day, it could be a Formal Clothes Factory .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SvVDqxqdBk8rRPz7l-FVGQ.png" /></figure><blockquote>Yep! You just save a day from a very indecisive client!</blockquote><h3>Takeaway 🗒</h3><ol><li>Abstract Factory Pattern is to provide an interface for a family of Products.</li><li>Clients don’t have to know which Product lines they’re having but they do know all the products are compatible!</li><li>When there’s need to extend a new series of products, just create a series of Concrete Products and a concrete Factory . (No breaking previous code)</li></ol><h3>What next❓</h3><p>There are still many other creational design patterns like Builder, Prototype…<br>We’ll talk about them in later articles.</p><p>Also, if you think this article helps you, claps down there!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fbutton.like.co%2Fin%2Fembed%2Fapbaca06%2Fbutton%2F&amp;display_name=LikeCoin&amp;url=https%3A%2F%2Fbutton.like.co%2Fapbaca06&amp;image=https%3A%2F%2Fstatic.like.co%2Flikecoin_de-portrait.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=like" width="485" height="212" frameborder="0" scrolling="no"><a href="https://medium.com/media/b46ced0c16bb367d12f38aa6e04e1e8e/href">https://medium.com/media/b46ced0c16bb367d12f38aa6e04e1e8e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32579472df69" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Factory Pattern<Design Pattern Series>]]></title>
            <link>https://medium.com/@cchen.co/simple-factory-pattern-design-pattern-series-2f8a35093567?source=rss-1b8a8ad37737------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f8a35093567</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[factory-pattern]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Cindy]]></dc:creator>
            <pubDate>Tue, 08 Sep 2020 08:04:18 GMT</pubDate>
            <atom:updated>2020-09-17T04:22:18.691Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*pKTAdlOW7vrJWYBc" /><figcaption>Photo by <a href="https://unsplash.com/@laurenmancke?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Lauren Mancke</a> on <a href="https://unsplash.com/s/photos/mac?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><strong><em>Writer’s Note: </em></strong><em>If you’re first time here, it’s a series about all the important design patterns that you should know.</em></p><p><em>Take a sip 🥃 Let’s dig in!</em></p><p>Today we’re talking about one of the creational patterns: <strong>Simple Factory Pattern</strong>. Here’s a UML of Simple Factory Pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*JVUSNH2SQs_pVK85ESQ03Q.png" /><figcaption>Simple Factory Pattern UML</figcaption></figure><p>Don’t worry if the above image is too frightening. We will explain it to you steps by steps later.</p><p>First, let’s figure out how Simple Factory Pattern helps us. 😻</p><h3>Why do we use Simple Factory Pattern❓</h3><p><strong>Simple Factory Pattern </strong>is one important creational design pattern.</p><p>It provides an interface for creating products in an abstract creator class.</p><ol><li><strong>Decrease coupling:</strong> Remove coupling between creator and concrete products</li><li><strong>Single responsibility: </strong>Product creation is now in each subclass.</li><li><strong>Easy to extend:</strong> New product type? Another product subclass will do.</li></ol><h3>When to use❓</h3><p>Use Simple Factory Pattern when <strong>you don’t know which concrete type you should work with.</strong></p><p>Creator will only <strong>depend on abstract product typ</strong>e without knowing which concrete type it’s dealing with.</p><h3>What does it do❓</h3><p><strong>Simple Factory Pattern</strong> separates concrete product initialization code from product business logic using a <strong>“Factory Method”</strong>.</p><p><strong>Factory Method: Each concrete creator returns a concrete product that conforms abstract Product type</strong></p><p>Now the product construction code is totally independent from business logic. Creator is clear from any product initialization code and only left with business logic to interact with the product!</p><p>Therefore, it’s easier to extend new products without breaking anything!</p><p><strong>👏👏👏 Hooray 👏👏👏</strong></p><p>If we want to extend the product series, we only need to create a new concrete creator and override the factory method<br>Isn’t it great? 😺</p><h3>How to do it❓</h3><p>Let’s take a garment factory, Wonderful Shape Clothe Factory, as an example.</p><p>Wonderful Shape Clothe Factory makes clothes for all over the world. But you know, people’s taste varies. 😕</p><p>Clothing styles for people from U.S and people from Europe are so different. It would be a mess if we try to wrap it up in one single Wonderful Shape Clothe Factory.</p><h4>1. Create Creator</h4><p>First, we make Wonderful Clothe Factory as our creator. And the factory method will be “ createClothe() ”<strong><br>🚩 Creator: Wonderful Clothe Factory<br>🚩 Factory Method: createClothe()</strong></p><h4>2. Add Product Interface</h4><p>We have to make different clothes for different areas. But no matter how distinguish the clothes are, they are still… clothes. So the interface is “Clothes”<strong><br></strong> <strong>🚩 &lt;&lt;interface&gt;&gt;Product: Clothe</strong></p><h4>3. Add Concrete Products</h4><p>From my observation, Europe people love Leather Jacket! U.S people love Hoodie! That’s it! <br><strong>🚩 Concrete Product A: Leather Jacket<br>🚩 Concrete Product B: Hoodie</strong><br>Also, both of them can zip up!</p><h4>4. Add Concrete Factory</h4><p>Specific factory with standard manufacture flow will help a lot! <br><strong>🚩 Concrete Creator A: Leather Jacket Factory<br>🚩 Concrete Creator B: Hoodie Factory</strong></p><blockquote>We have everything we need!</blockquote><p>Leather Jacket Factory will create Leather Jacket. :jacket<br>Hoodie Factory will create Hoodie.</p><p>Our client wouldn’t have to know in which factory their clothes are made. They only have to place an order. Wonderful Clothe Factory will make sure the clients get what they want. And their clothes can zip up whenever they want 😁</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*dKDZz1BQ1iwwyx5hi2frvQ.png" /><figcaption>Simple Factory Pattern Demo UML</figcaption></figure><h3>Takeaway 🗒</h3><ol><li>Simple Factory Pattern is to provide an interface for creating Products.</li><li>All concrete creators’ Factory Method create different types of Products</li><li>When there’s need to extend Product, just create another Concrete Product type.</li></ol><h3>What next❓</h3><p><strong><em>However, there’s still downside….</em></strong><br>Even though Simple Factory Pattern solves the spaghetti code for creating all kinds of products from the creator. (We save plenty of time for the boss of Wonderful Clothe Factory)</p><p>Still, we need a long “switch” or “ if…else” to determine which concrete creator we have to use. Right? 💁</p><p>No worry, here’s Abstract Factory Pattern to help 😉</p><p>And we’ll talk about it in the next article.</p><p>Now, just embrace the happiness that Simple Factory Pattern brings you ❤️</p><p>Also, if you think this article helps you, claps down there!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fbutton.like.co%2Fin%2Fembed%2Fapbaca06%2Fbutton%2F&amp;display_name=LikeCoin&amp;url=https%3A%2F%2Fbutton.like.co%2Fapbaca06&amp;image=https%3A%2F%2Fstatic.like.co%2Flikecoin_de-portrait.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=like" width="485" height="212" frameborder="0" scrolling="no"><a href="https://medium.com/media/b46ced0c16bb367d12f38aa6e04e1e8e/href">https://medium.com/media/b46ced0c16bb367d12f38aa6e04e1e8e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f8a35093567" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>