<?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: slj2222</title>
    <description>The latest articles on DEV Community by slj2222 (@slj2222).</description>
    <link>https://dev.to/slj2222</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%2F806913%2F128f1ed1-f0f7-4f79-bb91-f9a01368cffc.jpeg</url>
      <title>DEV Community: slj2222</title>
      <link>https://dev.to/slj2222</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/slj2222"/>
    <language>en</language>
    <item>
      <title>MVC - Model View Controller</title>
      <dc:creator>slj2222</dc:creator>
      <pubDate>Wed, 20 Apr 2022 18:05:08 +0000</pubDate>
      <link>https://dev.to/slj2222/mvc-model-view-controller-4aba</link>
      <guid>https://dev.to/slj2222/mvc-model-view-controller-4aba</guid>
      <description>&lt;p&gt;It is very important to know and understand what MVC, or the Model View Controller is when you are starting to learn Rails. MVC - Model View Controller is the architectural structure of Rails (and many other programming languages) projects that provides organization pattern, as well as an efficient means of separation of responsibilities. It is broken down into three parts, the model, the views, and the controllers. This blog will highlight what each part's role is and how they all work together. &lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Model&lt;/strong&gt;&lt;br&gt;
First, the model. Models are used to perform any business logic that is relevant to that specific model through ActiveRecord. Models communicate with the database to perform algorithms on the data (i.e. CRUD actions, create, read, update, delete). Most of the logic applied in the application will live in the model, including model relationships and validations. Models are classes that inherit from ApplicationRecord, which is a class that inherits from ActiveRecord::Base, which is what allows us to communicate to our database through the models.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Controller&lt;/strong&gt;&lt;br&gt;
Next, the controller. Controllers are the "middle man" in our application, which means they communicate between the data and the presentational parts of the application. They are responsible for determining how specific requests are handled. They will communicate with the model to retrieve data, then communicate that data with the view. Really, the controller is the engine behind the application that drives the experience between the web browser and our server. Each controller inherits from the ApplicationController, which is a class that inherits from ActionController::Base, which allows us to define actions that are associated with different routes in our application. For example, when our user makes a request at a particular route, our controller determines how to handle that request. Controllers will typically have a few different actions that are associated with an individual route. Each one of the actions will perform different behaviors by storing data inside an instance variable to be passed to the view. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;View&lt;/strong&gt;&lt;br&gt;
Finally, the View. The views are strictly the presentational parts of the application and they only contain code that is specific to what the user should see. The views do not contain complex code, as there is no direct communication to the database or the models. Again, the views only have one responsibility, which provides a strong and dynamic webpage for the user. &lt;/p&gt;




&lt;p&gt;Perhaps the most important part of the MVC is the naming convention. Here is a quick highlight of the naming conventions for each part of the MVC:&lt;/p&gt;

&lt;p&gt;Model - should be singular, followed by ".rb" &lt;br&gt;
(i.e. company.rb)&lt;/p&gt;

&lt;p&gt;Controller - should be a plural representation of the model, followed by ".rb"&lt;br&gt;
(i.e. company_controller.rb)&lt;/p&gt;

&lt;p&gt;View - should match the action named in the controller to provide an implicit render. &lt;br&gt;
(i.e. in the controller, there is a method called "show". The corresponding view should be called show.html.erb)&lt;/p&gt;




&lt;p&gt;Hopefully this intro helps better your understanding on the MVC, each part's role and how they all work together. &lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>mvc</category>
      <category>modelviewcontroller</category>
    </item>
    <item>
      <title>Instance Methods vs. Class Methods: What's the Difference?</title>
      <dc:creator>slj2222</dc:creator>
      <pubDate>Wed, 30 Mar 2022 19:37:50 +0000</pubDate>
      <link>https://dev.to/slj2222/instance-methods-vs-class-methods-whats-the-difference-4245</link>
      <guid>https://dev.to/slj2222/instance-methods-vs-class-methods-whats-the-difference-4245</guid>
      <description>&lt;p&gt;If you are starting your journey to becoming a software engineer, you will be introduced to Ruby at some point. If you find yourself struggling to differentiate between instances and class methods, this blog will hopefully help shed some light on the key differences between the two.&lt;/p&gt;

&lt;p&gt;Fist, let me explain what a class is. Ruby is an object-oriented programming language, right? A class is a blueprint from which objects, or instances are created. For example, if you had a class called MLB_team (MLB = Major League Baseball), each MLB team would be an instance of that class. Here is a diagram to assist:&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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fweuu3qytigiq20nnp3oo.png" 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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fweuu3qytigiq20nnp3oo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each instance, or team would have their own set of data depending on what columns are set up in the table - a topic for a different day. Some column examples might look like this:&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;MLB_team instance&lt;/strong&gt; -&amp;gt; &lt;em&gt;team_name, team_manager, team_location, total_wins, total_losses, stadium_capacity, world_series_wins, world_series_losses, etc...&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Now that we know what instances and classes are, now let me explain what methods are. A method is a set of expressions that return a value, very similar to a function in JavaScript.&lt;/p&gt;

&lt;p&gt;The first key difference - syntax. Instance methods are called on the instances. Class methods are called on the class and declared using the "self" keyword, seen below.&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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8j5q9s9wggk1ht9hwy9.png" 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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8j5q9s9wggk1ht9hwy9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instance methods can be used to add, update and display information corresponding to the specific instance, whereas class methods can be used to query select information from all of the instances in the class. &lt;/p&gt;

&lt;p&gt;In short, class methods are big-picture, looking at all the data in the class - every instance included. Instance methods are more specific, only looking at the specific instance.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>instance</category>
      <category>class</category>
      <category>methods</category>
    </item>
    <item>
      <title>React Components: Just Like Watching the News</title>
      <dc:creator>slj2222</dc:creator>
      <pubDate>Wed, 09 Mar 2022 21:15:49 +0000</pubDate>
      <link>https://dev.to/slj2222/react-components-just-like-watching-the-news-20nj</link>
      <guid>https://dev.to/slj2222/react-components-just-like-watching-the-news-20nj</guid>
      <description>&lt;p&gt;Many ideas in React are hard for beginners to wrap their heads around. For me, I had trouble understanding how React components work, but more specifically, how they work together. This analogy is designed to help you understand the following:&lt;/p&gt;

&lt;p&gt;1 - What are React components&lt;br&gt;
2 - How do React components work together to build an app.&lt;/p&gt;

&lt;p&gt;First, let me explain what React components are. React components are independent functions that accept inputs(i.e. props) and returns a React element that can be reused throughout your application. React applications use multiple components to ultimately give the app the look and functionality desired. There are parent components and children components, ultimately making up a React component tree, shown here:&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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1lyyn0ksrvdvazyfowqh.png" 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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1lyyn0ksrvdvazyfowqh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the components in this component tree work together to produce a wonderful application. Here is an image highlighting the different components on the Google homepage. Each highlighted component has its own functionality that adds a specific aspect of the page. When you bring all the components together, it gives you the desired look/functionality as a whole. After you have finished reading this blog, sketch out and send me what you think this component tree looks like.&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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxv1m5pdmw4jxggwszgwh.png" 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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxv1m5pdmw4jxggwszgwh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The analogy is this. Everyone has watched a news broadcast like NBC Nightly News. No matter which station you're watching, the daily broadcast, or show that you watch each day is the application for this analogy - the end result. Each show has a head news anchor sitting at a desk and reporting to you. They also have a whole team of news anchors that are sent out to report on various stories all around the world. The news anchors are the components - the individuals who have a story to report on. The head news anchor acts as the parent component, essentially driving the show, where as the various news anchors who are reporting on specific stories are the child components. The child components are reusable in this case because for tomorrows broadcast, they will be covering a different story. When all the news anchors do their job, they work together bringing you the end result, which is an hour long program that is executed the way it was designed - just like the React components do to create the application. &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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm2ptzy29z843bwazi4fg.png" 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/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm2ptzy29z843bwazi4fg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Life without .addEventListener()</title>
      <dc:creator>slj2222</dc:creator>
      <pubDate>Wed, 16 Feb 2022 21:31:17 +0000</pubDate>
      <link>https://dev.to/slj2222/life-without-addeventlistener-28mo</link>
      <guid>https://dev.to/slj2222/life-without-addeventlistener-28mo</guid>
      <description>&lt;p&gt;Can you imagine your life without .addEventListener()... probably not. Software Engineers/Developers know exactly what I'm talking about, but the general public has no idea how their lives would be effected if there were no event listeners. &lt;/p&gt;

&lt;p&gt;For those of you who are reading this and thinking to yourself, "what the heck is an event listener"? An event listener is "An event listener is a procedure in JavaScript that waits for an event to occur. The simple example of an event is a user clicking the mouse or pressing a key on the keyboard...an inbuilt function in JavaScript which takes the event to listen for, and a second argument to be called whenever the described event gets fired." -according to GeeksforGeeks.&lt;/p&gt;

&lt;p&gt;If you're still reading this and still thinking to yourself, "what the heck", let me further explain. Think about your most visited websites, apps on your phone, or you preferred social media platform (this list might be long). On your list, every one of the websites or apps is interactive, meaning there are places on the page that you can click on, either in the form of liking your friends photo, or something as boring as logging in to pay a bill. These features of your favorite websites/apps wouldn't be possible without event listeners. &lt;/p&gt;

&lt;p&gt;Event listeners are written in the code to make your experience the best it can be when visiting the webpage/app. They sit silent in the background waiting for you to commit the certain action on your screen that will trigger their attached set of instructions. For instance, once you double-click that photo of your friends cute little puppy on Instagram, everyone knows you liked the photo. This is because the "feature", we'll call it, was sitting in the code  not doing anything until you double-clicked the photo. Once you double-clicked the photo, the event listener (listening for the "double-click") fired off and executed a set of instructions. That set of instructions is a topic for another day.&lt;/p&gt;

&lt;p&gt;There are so many different "features" that are built into websites/apps that we all interact with on a daily basis. Like I said before, they are there to enhance our experiences while on the web, and they stem from even listeners.  &lt;/p&gt;

&lt;p&gt;The important thing is, imaging your life without an event listener waiting for you to double-click your friend's photo. If that is hard to imagine, imagine a website/app that you couldn't click on. How boring would that be? In my opinion, life would be MUCH different, without event listeners but again, that is a topic for another day. &lt;/p&gt;

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