<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Caio Tony</title>
    <description>The latest articles on DEV Community by Caio Tony (@kafircoder).</description>
    <link>https://dev.to/kafircoder</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F789518%2Ff408bc1a-44b5-4e53-98dd-ad8a03d56929.jpeg</url>
      <title>DEV Community: Caio Tony</title>
      <link>https://dev.to/kafircoder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kafircoder"/>
    <language>en</language>
    <item>
      <title>How to successfully decouple your frameworks from your business logic to improve testing and maintainability</title>
      <dc:creator>Caio Tony</dc:creator>
      <pubDate>Fri, 18 Feb 2022 14:24:41 +0000</pubDate>
      <link>https://dev.to/kafircoder/how-to-successfully-decouple-your-frameworks-from-your-business-logic-to-improve-testing-and-maintainability-1o5k</link>
      <guid>https://dev.to/kafircoder/how-to-successfully-decouple-your-frameworks-from-your-business-logic-to-improve-testing-and-maintainability-1o5k</guid>
      <description>&lt;p&gt;Hi Folks, Howdy?&lt;/p&gt;

&lt;p&gt;have you ever heard about &lt;strong&gt;&lt;em&gt;God Objects&lt;/em&gt;&lt;/strong&gt;? never? already? however, let me explain what a hell is this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In object-oriented programming, a &lt;strong&gt;&lt;em&gt;God Object&lt;/em&gt;&lt;/strong&gt; (sometimes also called an Omniscient or All-knowing object) is an object that &lt;strong&gt;references a large number of distinct types&lt;/strong&gt;, &lt;strong&gt;has too many unrelated or uncategorized methods&lt;/strong&gt;, or some combination of both. The God object is an example of an anti-pattern and a code smell. &lt;a href="https://en.wikipedia.org/wiki/God_object"&gt;&lt;em&gt;definition from wikipedia&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Turn your attention to the bolded sentence, this is the main problem of God objects and also the issue that turns it into anti-pattern/principle cause it notably is opposed to single-responsibility principle. let's look to a example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { postModel } from "../models/post";
import { Post } from "../types"
import express from "express";
import { Request, Response } from express
const router = express.Router()


class controller {
  static async handle (request: Request, response: Response): Promise&amp;lt;Post[]&amp;gt; {

   try{
    if (request["query"] == {}) {
      return response.status(400).json({
        statusCode: 400,
        message: "must inform query parameters"
      })
    }
    const { query } = request;
    const posts: Promise&amp;lt;Post[]&amp;gt; = await postModel.find(query).lean();

    return response.status(201).json(posts)
  }catch(err) {
    return response.status(500).json({
      statusCode: 500,
      message: "internal server error"
    })
  }

  }
}

router.get("/posts", controller.handle);

export controller;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
