<?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: Sean Francis N. Ballais</title>
    <description>The latest articles on DEV Community by Sean Francis N. Ballais (@seanballais).</description>
    <link>https://dev.to/seanballais</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F64976%2F3209d1af-f8ef-4a52-9ef9-5b821e1f0acd.jpg</url>
      <title>DEV Community: Sean Francis N. Ballais</title>
      <link>https://dev.to/seanballais</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/seanballais"/>
    <language>en</language>
    <item>
      <title>How and Why Do You Use GitHub Projects?</title>
      <dc:creator>Sean Francis N. Ballais</dc:creator>
      <pubDate>Fri, 07 Jun 2019 03:41:28 +0000</pubDate>
      <link>https://dev.to/seanballais/how-and-why-do-you-use-github-projects-1d9b</link>
      <guid>https://dev.to/seanballais/how-and-why-do-you-use-github-projects-1d9b</guid>
      <description>&lt;p&gt;I'm used to using Trello for project management, and I'm using it for a new project I'm working on. I encountered GitHub Projects just yesterday, and I'm wondering what its use case is or advantage over Trello (aside from it being under the same roof as your repos).&lt;/p&gt;

&lt;p&gt;For me, I see no significant advantage of it over Trello. The only scenario I would see that involves using GitHub Projects is when you would use Trello for general project management, with developer tasks delegated to GitHub Projects. However, I find that problematic since non-developers would not immediately know the progress and problems encountered during development, and devs would not be able to immediately know the progress and issues in non-dev-related tasks. You could duplicate items from GitHub Projects to Trello, but that would mean that there would be duplication of items, and additional work would be needed, unless there would be an integration between the two.&lt;/p&gt;

&lt;p&gt;I'd like to know your thoughts on GitHub Projects, and how and why you use it.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>I need help refactoring the database module where all the creation, insertion, etc. code are in their own respective files.</title>
      <dc:creator>Sean Francis N. Ballais</dc:creator>
      <pubDate>Mon, 25 Jun 2018 02:43:37 +0000</pubDate>
      <link>https://dev.to/seanballais/i-need-help-refactoring-the-database-module-where-all-the-creation-insertion-etc-code-are-in-their-own-respective-files-2cl1</link>
      <guid>https://dev.to/seanballais/i-need-help-refactoring-the-database-module-where-all-the-creation-insertion-etc-code-are-in-their-own-respective-files-2cl1</guid>
      <description>&lt;p&gt;&lt;strong&gt;NOTE: I was given permission to post the codes here.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I am in my internship currently. We are maintaining a system that is quite used in the organization. It is written in Java. I am assigned to refactoring the code and I chose to work on the database module, thinking it was &lt;em&gt;just&lt;/em&gt; an easy job to do.&lt;/p&gt;

&lt;p&gt;When I saw the code, it is full of singletons and I feel that the module could be done in a better way. One of the classes in the module is &lt;code&gt;InsertDatabase&lt;/code&gt;. It handles every data insertion. It looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InsertDatabase&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;InsertDatabase&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Properties&lt;/span&gt; &lt;span class="n"&gt;prop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Properties&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;InputStream&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;InsertDatabase&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileInputStream&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"textfile/sql_queries.txt"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;prop&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;load&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;err&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;InsertDatabase&lt;/span&gt; &lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InsertDatabase&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;insertIntoCourseTable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;course_abbr&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;course_name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cpInstance&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getConnection&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PreparedStatement&lt;/span&gt; &lt;span class="n"&gt;ps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;prepareStatement&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prop&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getProperty&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"insert_course_table"&lt;/span&gt;&lt;span class="o"&gt;));)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;course_abbr&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;course_name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;executeUpdate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

            &lt;span class="nc"&gt;Helper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;aprintln&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;Helper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LOG_VERBOSE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="nc"&gt;Helper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;aprintln&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;Helper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LOG_VERBOSE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"*** Information Added into Course Table***"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SQLException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Helper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;aprintln&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;Helper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LOG_VERBOSE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"Data already exists"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;close&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SQLException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;printStackTrace&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// more code...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is also the same case with the other classes assigned to table creation, updating data, and selecting data.&lt;/p&gt;

&lt;p&gt;The SQL queries are actually stored in a text file called &lt;code&gt;sql_queries.txt&lt;/code&gt; and is loaded in the variable &lt;code&gt;props&lt;/code&gt;. The text file is almost 200 lines long. Here's a sample line from the text file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;insert_diagnostic_table = insert into diagnostic_table (date_start, date_end, sem_num, freetime, time_penalty, balance_penalty) values (?, ?, ?, ?, ?, ?)
insert_pasa_balance_table = insert into pasa_balance_table (date_rendered, sender, amount, current_balance_sender, deducted_balance_sender, receiver, current_balance_receiver, added_balance_receiver) values (curdate(), ?, ?, ?, ?, ?, ?, ?)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The classes are then herded into a singleton class called &lt;code&gt;Information&lt;/code&gt;, which the system uses to interact with the database. The class looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Information&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Information&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;InsertDatabase&lt;/span&gt; &lt;span class="n"&gt;insert_db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;InsertDatabase&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;SearchDatabase&lt;/span&gt; &lt;span class="n"&gt;search_db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SearchDatabase&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;UpdateDatabase&lt;/span&gt; &lt;span class="n"&gt;update_db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;UpdateDatabase&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;DeleteDatabase&lt;/span&gt; &lt;span class="n"&gt;delete_db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DeleteDatabase&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;TransDatabase&lt;/span&gt; &lt;span class="n"&gt;trans_db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TransDatabase&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Information&lt;/span&gt; &lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Information&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/*
     * Here lies all of the methods that access DeleteDatabase
     */&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;storeToDeleteReservation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;delete_db&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;deleteReservation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// more code...&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;storeStudentToDelete&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;delete_db&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;deleteStudent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/**
     * Deletes Staff
     * @param username
     */&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;storeStaffToDelete&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;delete_db&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;deleteStaff&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/*
     * End of methods that access DeleteDatabase
     */&lt;/span&gt;

    &lt;span class="cm"&gt;/*
     * Here lies all the methods that access InsertDatabase
     */&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;storeAccountInfo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;mid_name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;suffix_name&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="n"&gt;insert_db&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;insertIntoAccountTable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mid_name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;suffix_name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;storeCourseInfo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;course_abbr&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;course_name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;insert_db&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;insertIntoCourseTable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;course_abbr&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;course_name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// more code...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have a weird feeling that there are problems with this. I can't pinpoint exactly what the problems are. Having them as singletons is a warning flag for me already. So, are there any problems with the approach?&lt;/p&gt;

&lt;p&gt;What I was thinking to do was to create a DAO (data access object) for each table and have the rest of the system use the DAOs instead. If I proceed with DAOs, I'd modify &lt;code&gt;Information&lt;/code&gt; first so that I would not touch the rest of the system and accidentally break anything. If I do break anything, at least I know where I screwed up. What do you think?&lt;/p&gt;

&lt;p&gt;Thanks! :)&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>I Made a Dev-Related Comic Strip - When You Add a New Feature Without Enough Tests</title>
      <dc:creator>Sean Francis N. Ballais</dc:creator>
      <pubDate>Sun, 03 Jun 2018 22:06:00 +0000</pubDate>
      <link>https://dev.to/seanballais/i-made-a-dev-related-comic-strip---when-you-add-a-new-feature-without-enough-tests-4cbj</link>
      <guid>https://dev.to/seanballais/i-made-a-dev-related-comic-strip---when-you-add-a-new-feature-without-enough-tests-4cbj</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bArv-FrJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://seanballais.github.io/static/img/posts/comic-strip-3-when-you-add-a-new-feature-without-enough-tests/comic-strip.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bArv-FrJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://seanballais.github.io/static/img/posts/comic-strip-3-when-you-add-a-new-feature-without-enough-tests/comic-strip.jpeg" alt="When You Add a New Feature Without Enough Tests"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What software projects have you worked on that doesn’t have tests? How was the experience? Let me know in the comments below.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;P.S. I also created two comic strips and wrote a few articles over at &lt;a href="https://seanballais.github.io/"&gt;my website&lt;/a&gt;. Go check them out!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>I am kind of baffled by this code in the `__init__.py` file in my Python project. How does this work internally?</title>
      <dc:creator>Sean Francis N. Ballais</dc:creator>
      <pubDate>Sat, 14 Apr 2018 14:44:33 +0000</pubDate>
      <link>https://dev.to/seanballais/i-got-surprised-by-this-code-in-the-init-file-in-my-python-package-how-does-this-work-internally-4ob0</link>
      <guid>https://dev.to/seanballais/i-got-surprised-by-this-code-in-the-init-file-in-my-python-package-how-does-this-work-internally-4ob0</guid>
      <description>&lt;p&gt;So, I have the following Python code residing in the &lt;code&gt;__init__.py&lt;/code&gt; file of my Python project which I autogenerated using PyScaffold.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;pkg_resources&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;get_distribution&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DistributionNotFound&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Change here if project is renamed and does not equal the package name
&lt;/span&gt;    &lt;span class="n"&gt;dist_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'mlfq-sim'&lt;/span&gt;
    &lt;span class="n"&gt;__version__&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_distribution&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dist_name&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;DistributionNotFound&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# pragma: no cover
&lt;/span&gt;    &lt;span class="c1"&gt;# Can't unit test this for now since I do not know how to temporarily
&lt;/span&gt;    &lt;span class="c1"&gt;# remove a distribution during runtime. Help. Also, is this even
&lt;/span&gt;    &lt;span class="c1"&gt;# worth it?
&lt;/span&gt;    &lt;span class="n"&gt;__version__&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'unknown'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I get that it gets the version of my project. But how does it do it? Is there a benefit in using it compared to the one below?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;__version__&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'some version'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>discuss</category>
      <category>python</category>
      <category>setuptools</category>
    </item>
    <item>
      <title>How can I improve this while loop code snippet?</title>
      <dc:creator>Sean Francis N. Ballais</dc:creator>
      <pubDate>Sun, 08 Apr 2018 08:26:59 +0000</pubDate>
      <link>https://dev.to/seanballais/how-can-i-improve-this-while-loop-code-snippet-2o4n</link>
      <guid>https://dev.to/seanballais/how-can-i-improve-this-while-loop-code-snippet-2o4n</guid>
      <description>&lt;p&gt;So, I have this code snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="nc"&gt;Character&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isWhitespace&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;charAt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;currentCharIndex&lt;/span&gt;&lt;span class="o"&gt;)))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;charAt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;currentCharIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What it does is just basically loops through a string until it hits a white space character.&lt;/p&gt;

&lt;p&gt;However, I find the code a bit messy. &lt;strong&gt;How can I improve it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I can try this code snippet instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;charAt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;currentCharIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="nc"&gt;Character&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isWhitespace&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;charAt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;currentCharIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks cleaner but &lt;code&gt;this.source.charAt(this.currentCharIndex)&lt;/code&gt; seems redundant (the same as the previous snippet) so I need your opinion on how you would tackle this problem.&lt;/p&gt;

&lt;p&gt;Thanks! :D&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>I'm considering to use vim or neovim as my primary text editor. Any tips?</title>
      <dc:creator>Sean Francis N. Ballais</dc:creator>
      <pubDate>Tue, 03 Apr 2018 09:35:49 +0000</pubDate>
      <link>https://dev.to/seanballais/im-considering-to-use-vim-or-neovim-as-my-primary-text-editor-any-tips-1jj6</link>
      <guid>https://dev.to/seanballais/im-considering-to-use-vim-or-neovim-as-my-primary-text-editor-any-tips-1jj6</guid>
      <description>&lt;p&gt;I've been using VS Code as my primary text editor. Before, I have been using JetBrains's IDEs, Atom, and Sublime Text. I moved from IDEs to VS Code because a text editor is lighter than any IDE. I initially came from Atom. However, upon discovering and giving VS Code a shot, I was immediately hooked.&lt;/p&gt;

&lt;p&gt;I've noticed that I'm using the terminal a lot these days. I wondered if I could use a terminal-based text editor instead. I think it makes perfect sense since I'm also using the terminal a lot. The text editor I have decided upon using is Vim. I also found out about Neovim minutes before I wrote this #discuss item. I think I'll use that instead of just vim.&lt;/p&gt;

&lt;p&gt;So, any tips, things I should know, and/or fair warnings in using vim/neovim? What are your experiences in using any of the two?&lt;/p&gt;

&lt;p&gt;Thanks! :)&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Implementing a Simple Message Bus in C++</title>
      <dc:creator>Sean Francis N. Ballais</dc:creator>
      <pubDate>Tue, 03 Jan 2017 14:33:00 +0000</pubDate>
      <link>https://dev.to/seanballais/implementing-a-simple-message-bus-in-c-1pa5</link>
      <guid>https://dev.to/seanballais/implementing-a-simple-message-bus-in-c-1pa5</guid>
      <description>&lt;p&gt;&lt;strong&gt;Note: Alternative URL to the original post &lt;a href="http://seanballais.github.io/blog/implementing-a-simple-message-bus-in-cpp/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Starting late December of 2016, I have been working on creating a 2D game engine for fun (and profit). It is not done yet. Most of the systems have not yet been implemented. &lt;a href="http://seanballais.github.io/blog/box2d-and-the-pixel-per-meter-ratio/" rel="noopener noreferrer"&gt;Integration between graphics and physics&lt;/a&gt; is nonexistent. Key core components are nothing but ideas of the mind. What I recently finished working on was the message bus. It is already functional but it still needs improvement.&lt;/p&gt;

&lt;p&gt;A message bus acts like the communication gateway between two or more components in a program, may it be business-oriented applications, or games. Without it, components can tend to couple themselves, and create a messy looking architecture.&lt;/p&gt;

&lt;p&gt;In this article, we will be implementing a game-oriented message bus that you can use in your own project. Many applications, game engines, and games are written in C++ so we will be using that language. I recommend using C++14 because it is the latest C++ standard but this will compile in C++11 too.&lt;/p&gt;

&lt;h4&gt;
  
  
  What’s a Message Bus?
&lt;/h4&gt;

&lt;p&gt;Applications and games normally are composed of multiple components. Each component is responsible for a task or a feature of the application. Sometimes, a component needs to ‘talk’ to another component. For example, your input system would need to “tell” your entity system that the player needs to be moved forward because the &lt;code&gt;W&lt;/code&gt; key has been pressed. In code, you might implement it in this manner.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Somewhere in the depths of your Input system.
if (Input.isPressed(Keys.W)) {
    Log.add("Siopao! Siopao! Siopao! Do not do it this way! Siopao! Siopao! Siopao!");
    player.move(10, 10);
    ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, your input system is now informing the player to move forward. Game runs perfectly but there is a problem. Doing so couples your code. Coupled code is hard to maintain and is messy. Adding and removing certain parts would be more difficult as one change could entail changes in the other components. Creating a diagram on the overall system could result in each component connected to each other component. It looks messy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fseanballais.github.io%2F%2Fstatic%2Fimg%2Fposts%2Fimplementing-a-simple-message-bus-in-cpp%2Fmessy-coupling.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fseanballais.github.io%2F%2Fstatic%2Fimg%2Fposts%2Fimplementing-a-simple-message-bus-in-cpp%2Fmessy-coupling.jpg" alt="Coupled components"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To solve this issue, we would need to decouple the components from each other. A system that will allow communication between these components is what we need. This system is what we call a message bus.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;message bus&lt;/strong&gt; is basically a modified large-scale &lt;a href="http://gameprogrammingpatterns.com/observer.html" rel="noopener noreferrer"&gt;Observer pattern&lt;/a&gt;. In the Observer pattern, there would be &lt;strong&gt;observers&lt;/strong&gt; to receive notifications and &lt;strong&gt;subjects&lt;/strong&gt; to send those notifications.&lt;/p&gt;

&lt;p&gt;In a message bus, you have components sending and receiving messages to it. The message bus’s job is to route these messages to every component connected to it. &lt;strong&gt;Messages&lt;/strong&gt; that each component send are basically events that happened. For example, a component may send a &lt;code&gt;W_PRESSED&lt;/code&gt; message and the message bus will send that message to other components. The receipient is responsible with what it will do with the message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fseanballais.github.io%2F%2Fstatic%2Fimg%2Fposts%2Fimplementing-a-simple-message-bus-in-cpp%2Fmessagebus.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fseanballais.github.io%2F%2Fstatic%2Fimg%2Fposts%2Fimplementing-a-simple-message-bus-in-cpp%2Fmessagebus.jpg" alt="Architecture based around a message bus"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One cool thing about message buses is that the sender does not even need to know if the message was received by another component or not. Heck! The sender should only be aware of the existence of itself and the message bus. It should not know the existence of the other components. The sent message can be silently ignored by the receivers (if there are any).&lt;/p&gt;

&lt;h4&gt;
  
  
  Implementing a Message Bus
&lt;/h4&gt;

&lt;p&gt;Time to for the part you have been waiting for - implementing the message bus. The code here is adapted from the &lt;code&gt;MessageBus&lt;/code&gt; component I have in my engine. We would start with implementing the &lt;code&gt;Message&lt;/code&gt; class. We can implement it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Message
{
public:
    Message(const std::string event)
    {
        messageEvent = event;
    }

    std::string getEvent()
    {
        return messageEvent;
    }
private:
    std::string messageEvent;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Message&lt;/code&gt; constructor accepts the string parameter &lt;code&gt;event&lt;/code&gt; that contains the event that happened. The value of &lt;code&gt;messageEvent&lt;/code&gt; can be something like &lt;code&gt;W_PRESSED&lt;/code&gt; or &lt;code&gt;PLAYER_FELL&lt;/code&gt;. Note that this implementation may differ from yours depending on your needs.&lt;/p&gt;

&lt;p&gt;Next, we will implement the message bus itself where all components are connected to. This is how we can implement the message bus.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;functional&amp;gt;
#include &amp;lt;queue&amp;gt;
#include &amp;lt;vector&amp;gt;

class MessageBus
{
public:
    MessageBus() {};
    ~MessageBus() {};

    void addReceiver(std::function&amp;lt;void (Message)&amp;gt; messageReceiver)
    {
        receivers.push_back(messageReceiver);
    }

    void sendMessage(Message message)
    {
        messages.push(message);
    }

    void notify()
    {
        while(!messages.empty()) {
            for (auto iter = receivers.begin(); iter != receivers.end(); iter++) {
                (*iter)(messages.front());
            }

            messages.pop();
        }
    }

private:
    std::vector&amp;lt;std::function&amp;lt;void (Message)&amp;gt;&amp;gt; receivers;
    std::queue&amp;lt;Message&amp;gt; messages;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, that’s aplenty! Let’s explain what each function does.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;addReceiver()&lt;/code&gt;
This function adds a new receiver to the list of receivers &lt;code&gt;notify()&lt;/code&gt; will loop through. A receiver is basically another component connected to the message bus. All receivers are stored in the &lt;code&gt;receivers&lt;/code&gt; vector. This function should be called during the initialization of your program. We are accepting &lt;code&gt;std::function&lt;/code&gt; objects so that we will be able to accept receivers that do not inherit from some sort of an &lt;code&gt;Observer&lt;/code&gt; class. Also, the function name we pass can be different as long as the function has the same signature.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sendMessage()&lt;/code&gt;
Adds a new message that the message bus will send to each component. All messages are added in a queue (&lt;code&gt;messages&lt;/code&gt; in our case). We are using a queue so that we are guaranteed that messages are sent using FIFO (first in, first out). You do not want to be killed by an enemy first even though you killed him first, don’t you? This function is invoked by the component itself that has a reference to the message bus.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;notify()&lt;/code&gt;
This function sends all messages to each component. The first message in the queue is the first to be sent to each component and then popped off the message queue and so on. This function should be called during the game loop.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, we would need a base class where all components that uses the message bus will be based on. We will call this base class, &lt;code&gt;BusNode&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;functional&amp;gt;

class BusNode
{
public:
    BusNode(MessageBus *messageBus)
    {
        this-&amp;gt;messageBus = messageBus;
        this-&amp;gt;messageBus-&amp;gt;addReceiver(this-&amp;gt;getNotifyFunc());
    }

    virtual void update() {};
protected:
    MessageBus *messageBus;

    std::function&amp;lt;void (Message)&amp;gt; getNotifyFunc()
    {
        auto messageListener = [=](Message message) -&amp;gt; void {
            this-&amp;gt;onNotify(message);
        };
        return messageListener;
    }

    void send(Message message)
    {
        messageBus-&amp;gt;sendMessage(message);
    }

    virtual void onNotify(Message message)
    {
        // Do something here. Your choice. You could do something like this.
        // std::cout &amp;lt;&amp;lt; "Siopao! Siopao! Siopao! (Someone forgot to implement onNotify().)" &amp;lt;&amp;lt; std::endl;
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Upon construction of a &lt;code&gt;BusNode&lt;/code&gt; object, it will add its receiver function, &lt;code&gt;onNotify&lt;/code&gt;, to the message bus so that it can begin receiving messages automatically. We have to use &lt;code&gt;getNotifyFunc()&lt;/code&gt; to pass a &lt;code&gt;std::function&lt;/code&gt; object containing a lambda function that calls our object’s &lt;code&gt;onNotify()&lt;/code&gt;. The &lt;code&gt;update()&lt;/code&gt; function is where we would perform update routines in our component.&lt;/p&gt;

&lt;p&gt;We have now implemented a rudimentary message bus. You can now use this in your project and remix it according to your needs. But to finish this section on a high note, let’s create a simple example using those three classes we have built. Don’t forget to compile this under C++11 or C++14.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;functional&amp;gt;
#include &amp;lt;queue&amp;gt;
#include &amp;lt;vector&amp;gt;

class Message
{
public:
    Message(const std::string event)
    {
        messageEvent = event;
    }

    std::string getEvent()
    {
        return messageEvent;
    }
private:
    std::string messageEvent;
};

class MessageBus
{
public:
    MessageBus() {};
    ~MessageBus() {};

    void addReceiver(std::function&amp;lt;void (Message)&amp;gt; messageReceiver)
    {
        receivers.push_back(messageReceiver);
    }

    void sendMessage(Message message)
    {
        messages.push(message);
    }

    void notify()
    {
        while(!messages.empty()) {
            for (auto iter = receivers.begin(); iter != receivers.end(); iter++) {
                (*iter)(messages.front());
            }

            messages.pop();
        }
    }

private:
    std::vector&amp;lt;std::function&amp;lt;void (Message)&amp;gt;&amp;gt; receivers;
    std::queue&amp;lt;Message&amp;gt; messages;
};

class BusNode
{
public:
    BusNode(MessageBus *messageBus)
    {
        this-&amp;gt;messageBus = messageBus;
        this-&amp;gt;messageBus-&amp;gt;addReceiver(this-&amp;gt;getNotifyFunc());
    }

    virtual void update() {}
protected:
    MessageBus *messageBus;

    std::function&amp;lt;void (Message)&amp;gt; getNotifyFunc()
    {
        auto messageListener = [=](Message message) -&amp;gt; void {
            this-&amp;gt;onNotify(message);
        };
        return messageListener;
    }

    void send(Message message)
    {
        messageBus-&amp;gt;sendMessage(message);
    }

    virtual void onNotify(Message message)
    {
        // Do something here. Your choice. But you could do this.
        // std::cout &amp;lt;&amp;lt; "Siopao! Siopao! Siopao! (Someone forgot to implement onNotify().)" &amp;lt;&amp;lt; std::endl;
    }
};

// This class will receive a message from ComponentB.
class ComponentA : public BusNode
{
public:
    ComponentA(MessageBus* messageBus) : BusNode(messageBus) {}

private:
    void onNotify(Message message)
    {
        std::cout &amp;lt;&amp;lt; "I received: " &amp;lt;&amp;lt; message.getEvent() &amp;lt;&amp;lt; std::endl;
    }
};

// This class will send a message to ComponentA.
class ComponentB : public BusNode
{
public:
    ComponentB(MessageBus* messageBus) : BusNode(messageBus) {}

    void update()
    {
        Message greeting("Hi!");
        send(greeting);
    }

private:
    void onNotify(Message message)
    {
        std::cout &amp;lt;&amp;lt; "I received: " &amp;lt;&amp;lt; message.getEvent() &amp;lt;&amp;lt; std::endl;
    }
};

int main()
{
    MessageBus messageBus;
    ComponentA compA(&amp;amp;messageBus);
    ComponentB compB(&amp;amp;messageBus);

    // This is supposed to act like a game loop.
    for (int ctr = 0; ctr &amp;lt; 50; ctr++) {
        compA.update();
        compB.update();
        messageBus.notify();
    }

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output would look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fseanballais.github.io%2Fstatic%2Fimg%2Fposts%2Fimplementing-a-simple-message-bus-in-cpp%2Fexample-output.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fseanballais.github.io%2Fstatic%2Fimg%2Fposts%2Fimplementing-a-simple-message-bus-in-cpp%2Fexample-output.jpg" alt="Message Bus example output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;We have implemented a message bus that allows intercomponent communication and decoupling of our system. Our message bus consists of three classes: &lt;code&gt;BusNode&lt;/code&gt;, the base class for our components depending on the message bus; &lt;code&gt;Message&lt;/code&gt;, the class the messages we send depends on; and &lt;code&gt;MessageBus&lt;/code&gt;, the message bus implementation itself.&lt;/p&gt;

&lt;p&gt;What we created is just a basic message bus. The message bus is usable but it surely needs improvements. One way you can build upon this is by adding a mechanism where receivers can subscribe to specific messages. To allow comparison between messages, we can use message IDs. The IDs should be hashed (try FNV-1A) to allow fast comparisons.&lt;/p&gt;

&lt;p&gt;For further reference, you may want to check out OpTank’s &lt;a href="http://optank.org/2013/04/02/game-development-design-3-message-bus/" rel="noopener noreferrer"&gt;article&lt;/a&gt; on message buses. Michael Kissner’s &lt;a href="http://gamasutra.com/blogs/MichaelKissner/20151027/257369/Writing_a_Game_Engine_from_Scratch__Part_1_Messaging.php" rel="noopener noreferrer"&gt;article&lt;/a&gt; about messaging in a game engine in Gamasutra can be helpful as well.&lt;/p&gt;

&lt;p&gt;Do not take what we have created as is. I intended it as a foundation from which you can build your own message bus. I recommend deviating from the code here. Do not forget to &lt;a href="https://dev.to/blog/5-lessons-learned-from-developing-a-school-election-system/"&gt;plan before you code&lt;/a&gt;. Adapt what you have learned here and apply it in your own message bus or any project you have at hand.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Are you currently working on a project? How did you process communication between your project’s components? Do you have something to share? Let us know in the comments below.&lt;/em&gt;&lt;/p&gt;

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