<?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 cyb3rh4wk on Medium]]></title>
        <description><![CDATA[Stories by cyb3rh4wk on Medium]]></description>
        <link>https://medium.com/@cyb3rh4wk?source=rss-34ee9045a034------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hYx61aaUCRE9Fyvl</url>
            <title>Stories by cyb3rh4wk on Medium</title>
            <link>https://medium.com/@cyb3rh4wk?source=rss-34ee9045a034------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:38:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cyb3rh4wk/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 Rails — Introduction]]></title>
            <link>https://cyb3rh4wk.medium.com/abstract-rails-introduction-dff2d61d3279?source=rss-34ee9045a034------2</link>
            <guid isPermaLink="false">https://medium.com/p/dff2d61d3279</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[service-object]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[cyb3rh4wk]]></dc:creator>
            <pubDate>Fri, 08 May 2020 02:09:23 GMT</pubDate>
            <atom:updated>2020-05-08T02:09:23.399Z</atom:updated>
            <content:encoded><![CDATA[<h3>Abstract Rails — Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C8xjdHvZn7Pns7hWlhc8Dw.jpeg" /></figure><p>Long ago…when we started our first Rails Web Application, we have used controllers, models, views(.erb files), routes, etc to build an end-to-end application. As a beginner, it came as a habit to write most of our code in controller action methods (because it was easy to do so :P). Should we have known of the <strong>Thin-controller Fat-model(TCFM) </strong>design pattern, our codebase would have been better of.</p><p>After learning &amp; implementing TCFM, and as our web app kept growing in terms of the number of functionalities, we are going to be hit by a new problem, <strong>Obese-models </strong>(this is made up :D). We now had models which took a lifetime to scroll and extensive use of this practice also lead to redundant codes, less readability, slower understanding for other developers. Now, we had to think of abstracting the functionalities of the model in a way that these are intuitive, readable, and following a linear flow, etc i.e. making the models thin.</p><p>To achieve that, here are some abstraction techniques or also known as Design Patterns,</p><ul><li>Service Objects</li><li>Concerns</li><li>Query Objects</li><li>Policy Objects</li><li>Factory Method</li><li>Strategy</li></ul><p>We will go through a short explanation of these patterns,</p><h3>Service Objects</h3><p>Service objects are created when the business logic is not the responsibility of some specific model(s)/controller(s), when the logic is fairly complex, uses several models, uses APIs for third-party services.</p><p>Service objects are going to be the most useful implementations in making your codebase readable, modular, and easily maintainable.</p><h3>Concerns</h3><p>Concerns are not exactly a design pattern. It is a provision by ActiveSupport library for including modules in classes i.e. creating mixins.</p><blockquote><strong>NOTE:</strong> It is suggested to avoid using concerns. I will be explaining the reasons in upcoming blogs.</blockquote><h3>Query Objects</h3><p>Query Object is a pattern that lets us extract common query logic from controllers/models and into reusable classes.</p><h3>Policy Objects</h3><p>Policy Object is similar to a Service Object but with the responsibility of read operations. Service Object, on the other hand, is responsible for write operations. Policy Objects encapsulate complex business rules and can easily be replaced by another Policy Objects with different rules</p><h3>Factory Method</h3><p>Factory method is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects created</p><h3>Strategy</h3><p>Strategy is a behavioral design pattern that lets you define a family of algorithms, put together into a separate class, and make their objects interchangeable.</p><p>Strategy pattern suggests that you take a class that does something specific in a lot of different ways and extract all of these algorithms into separate classes called <em>strategies</em>. The original class, called context must have a field for storing a reference to one of the strategies.</p><p>Apart from these design patterns, there are also others like Prototype, Observer, State, Decorator, Adapter, etc which will discuss in detail in the upcoming posts.</p><p><strong>Upcoming Post:</strong> Abstract Rails — What and How of Services</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dff2d61d3279" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>