<?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 Lucas Daru Miguel on Medium]]></title>
        <description><![CDATA[Stories by Lucas Daru Miguel on Medium]]></description>
        <link>https://medium.com/@lucas.prof?source=rss-436c1646a0d7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6kWKgJLuLUDrI1qxZ-7AbQ.png</url>
            <title>Stories by Lucas Daru Miguel on Medium</title>
            <link>https://medium.com/@lucas.prof?source=rss-436c1646a0d7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:18:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lucas.prof/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[Decorator in Go]]></title>
            <link>https://medium.com/@lucas.prof/decorator-in-go-7cfa50393758?source=rss-436c1646a0d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cfa50393758</guid>
            <category><![CDATA[golang-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[golang-patterns]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <dc:creator><![CDATA[Lucas Daru Miguel]]></dc:creator>
            <pubDate>Thu, 21 Mar 2024 00:15:45 GMT</pubDate>
            <atom:updated>2024-03-21T00:15:45.682Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*fN5nD3xOhdp2t7TwoW1l8w.gif" /><figcaption>Look at decorators as the spooky decorations that transform your software into a haunted mansion of endless possibilities!</figcaption></figure><blockquote>Think of your software as a busy office building with different departments like <strong>Sales</strong>, <strong>HR</strong>, and <strong>IT</strong>. <br> Using decorators is like giving each department its own set of superpowers! You start with a basic department setup, and then you can layer on special abilities (decorators) as needed.</blockquote><blockquote>Want to give the sales team the ability to <strong>View, Edit, </strong>and<strong> Delete</strong> data?</blockquote><blockquote>No problem!!!, just add those skills as <strong>decorators</strong>!!! 😃 Or maybe the <strong>HR</strong> team only needs to <strong>view</strong> and <strong>delete</strong> data, with no editing allowed.</blockquote><blockquote>😜Easy!!! You can customize each department’s capabilities by stacking the right decorators on top of each other. And because everything follows the same playbook (<strong>interface</strong>), you can mix and match decorators to create the perfect setup for each department. It’s like giving each team their own unique toolkit, tailored to their specific needs.</blockquote><blockquote>This flexible approach makes your software more customizable, easier to maintain, and just plain awesome!</blockquote><p>Let’s GO:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*1UbPN7rpmLg-CxwCDrjlSA.gif" /></figure><pre>package main<br><br>import &quot;fmt&quot;<br><br>// Structure representing access permissions for a department<br>type DepartmentPermissions struct {<br>    View   bool<br>    Edit   bool<br>    Delete bool<br>}<br><br>// Base access interface<br>type Access interface {<br>    GetPermissions() DepartmentPermissions<br>}<br><br>// Base implementation<br>type BaseAccess struct{}<br><br>func (b *BaseAccess) GetPermissions() DepartmentPermissions {<br>    return DepartmentPermissions{<br>        View:   true,<br>        Edit:   true,<br>        Delete: true,<br>    }<br>}<br><br>// Decorator for the Sales department<br>type SalesDecorator struct {<br>    Access<br>}<br><br>func (s *SalesDecorator) GetPermissions() DepartmentPermissions {<br>    permissions := s.Access.GetPermissions()<br>    // In the example, let&#39;s deny the delete permission for the Sales department<br>    permissions.Delete = false<br>    return permissions<br>}<br><br>// Decorator for the HR department<br>type HRDecorator struct {<br>    Access<br>}<br><br>func (h *HRDecorator) GetPermissions() DepartmentPermissions {<br>    permissions := h.Access.GetPermissions()<br>    // In the example, let&#39;s deny the edit permission for the HR department<br>    permissions.Edit = false<br>    return permissions<br>}<br><br>func main() {<br>    // Creating a base access object<br>    baseAccess := &amp;BaseAccess{}<br><br>    // Decorating access for the Sales department<br>    salesAccess := &amp;SalesDecorator{Access: baseAccess}<br>    salesPermissions := salesAccess.GetPermissions()<br>    fmt.Println(&quot;Sales Department Permissions:&quot;)<br>    fmt.Println(&quot;View:&quot;, salesPermissions.View)<br>    fmt.Println(&quot;Edit:&quot;, salesPermissions.Edit)<br>    fmt.Println(&quot;Delete:&quot;, salesPermissions.Delete)<br><br>    // Decorating access for the HR department<br>    hrAccess := &amp;HRDecorator{Access: baseAccess}<br>    hrPermissions := hrAccess.GetPermissions()<br>    fmt.Println(&quot;\nHR Department Permissions:&quot;)<br>    fmt.Println(&quot;View:&quot;, hrPermissions.View)<br>    fmt.Println(&quot;Edit:&quot;, hrPermissions.Edit)<br>    fmt.Println(&quot;Delete:&quot;, hrPermissions.Delete)<br>}</pre><p>Output:</p><pre>Sales Department Permissions:<br>View: true<br>Edit: true<br>Delete: false<br><br>HR Department Permissions:<br>View: true<br>Edit: false<br>Delete: true</pre><blockquote><strong>Conclusion</strong>:</blockquote><blockquote>In a nutshell, decorators are like magical add-ons for your software. They let you customize different parts of your code without making a mess. Just think of them as special toppings you can layer onto your favorite ice cream sundae — each one adds its own flavor and makes your dessert even more delicious! By using decorators, you can give your software superpowers, making it more flexible, adaptable, and fun to work with. So next time you’re coding, remember to sprinkle on some decorators and watch your creations come to life!</blockquote><p><em>Written by </em><a href="https://www.linkedin.com/in/lucas-daru-miguel-642901233/"><strong><em>Lucas Daru Miguel</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cfa50393758" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>