<?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: kimbi619</title>
    <description>The latest articles on DEV Community by kimbi619 (@kimbi619).</description>
    <link>https://dev.to/kimbi619</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%2F612770%2F92a2deae-65ec-440e-b153-1957271b68e5.png</url>
      <title>DEV Community: kimbi619</title>
      <link>https://dev.to/kimbi619</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kimbi619"/>
    <language>en</language>
    <item>
      <title>Introduction to system design patterns</title>
      <dc:creator>kimbi619</dc:creator>
      <pubDate>Sun, 10 Mar 2024 23:24:06 +0000</pubDate>
      <link>https://dev.to/kimbi619/introduction-to-system-design-patterns-gm4</link>
      <guid>https://dev.to/kimbi619/introduction-to-system-design-patterns-gm4</guid>
      <description>&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%2F7an8l7ygiqe5zqe4p9q8.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%2F7an8l7ygiqe5zqe4p9q8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When designing software applications there are a set of recurring problems that one may do several times. These problems form a pattern for most complex and robust systems and a set of design patterns were developed. One of the main reasons why computer science researchers began to recognize design patterns was to satisfy the need for good simple and reusable solutions. These are known as the software or system design patterns.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what exactly are Software design patterns
&lt;/h2&gt;

&lt;p&gt;In simple terms, design patterns are recurring solutions to design problems you see over and over. They constitute a set of rules (or perhaps guidelines ) describing how to accomplish certain tasks in the realm of software development.&lt;br&gt;
Design patterns exist on many levels, from very low-level specific solutions to broadly generalized system architectures and hundreds of these were developed through the years to attack these problems. However, only a few of them are utilized in today's system designs&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Design Patterns
&lt;/h2&gt;

&lt;p&gt;Design patterns can be grouped into three groups which are creational, structural, and behavioral patterns which all talk about the same thing at the core that is object inheritance and containement in Object Oriented Programming (OOP). I will explain how to choose the best pattern in the next session.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Creational patterns
&lt;/h2&gt;

&lt;h2&gt;
  
  
  A. Singleton
&lt;/h2&gt;

&lt;p&gt;Ensure a class only has one instance, and provide a global point of access to it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation:&lt;/strong&gt;&lt;br&gt;
It’s important for some classes to have exactly one instance. How do we ensure that a class has only one instance and that the instance is easily accessible? A global&lt;br&gt;
variable makes an object accessible, but it doesn’t keep you from instantiating multiple objects.&lt;br&gt;
A better solution is to make the class itself responsible for keeping track of its sole instance. The class&lt;br&gt;
can ensure that no other instance can be created (by intercepting requests to create new objects), and it&lt;br&gt;
can provide a way to access the instance. This is the Singleton pattern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applicability:&lt;/strong&gt;&lt;br&gt;
there must be exactly one instance of a class, and it must be accessible to clients from a well-known access point.&lt;br&gt;
when the sole instance should be extensible by subclassing, and clients should be able to use an extended instance without modifying their code.&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%2Fa84cpahu2cz8p98wo2bn.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%2Fa84cpahu2cz8p98wo2bn.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some of the benefits of this pattern include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Controlled access to the sole instance. Because the Singleton class encapsulates its sole instance, it can have strict control over how and when clients access it&lt;/li&gt;
&lt;li&gt;Reduced name space. The Singleton pattern is an improvement over global variables. It avoids polluting the namespace with global variables that store sole instances.&lt;/li&gt;
&lt;li&gt;Permits a variable number of instances&lt;/li&gt;
&lt;li&gt;Permits refinement of operations and representations&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  B. Prototype pattern
&lt;/h2&gt;

&lt;p&gt;Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. this in simple words means hiding the complexity of the object using a prototype&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motivation&lt;/strong&gt;&lt;br&gt;
Use the Prototype pattern when a system should be independent of how its products are created, composed, and represented; and&lt;br&gt;
When the classes to instantiate are specified at run-time, for example, by dynamic loading; or&lt;br&gt;
To avoid building a class hierarchy of factories that parallels the class hierarchy of products; or&lt;br&gt;
When instances of a class can have one of only a few different combinations of state. It may be more convenient to install a corresponding number of prototypes and clone them rather than instantiating the class manually, each time with the appropriate state.&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%2Fdy6s4fqht857qph54hu8.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%2Fdy6s4fqht857qph54hu8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  C. Builder pattern
&lt;/h2&gt;

&lt;p&gt;Separate the construction of a complex object from its representation so that the same construction process can create different representations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use the Builder pattern when&lt;/strong&gt;&lt;br&gt;
The algorithm for creating a complex object should be independent of the parts that make up the object and how they’re assembled.&lt;br&gt;
The construction process must allow different representations for the object that’s constructed.&lt;br&gt;
To better explain, this means the Builder Pattern promotes algorithm independence, allowing for flexibility in the construction process, and enables the creation of objects with different representations without modifying the client code. It’s particularly beneficial when dealing with complex objects that have multiple optional components or configuration&lt;/p&gt;

&lt;h2&gt;
  
  
  D. Abstract Factory Pattern ( aka Kit )
&lt;/h2&gt;

&lt;p&gt;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&lt;/p&gt;

&lt;p&gt;Use the Abstract Factory pattern when&lt;br&gt;
A system should be independent of how its products are created, composed, and represented.&lt;br&gt;
A system should be configured with one of multiple families of products.&lt;br&gt;
A family of related product objects is designed to be used together, and you need to enforce this constraint.&lt;br&gt;
A you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations.&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%2Flnobg3e0mcdty06h7az1.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%2Flnobg3e0mcdty06h7az1.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The Abstract Factory pattern has the following benefits and liabilities:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It isolates concrete classes&lt;/li&gt;
&lt;li&gt;It promotes consistency among products.&lt;/li&gt;
&lt;li&gt;It makes exchanging product families easy. The class of a concrete factory appears only once in an application — that is, where it’s instantiated. This makes it easy to change the concrete factory an application uses&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Factory Method Design Pattern (aka Virtual Contructor)
&lt;/h2&gt;

&lt;p&gt;Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses&lt;/p&gt;

&lt;p&gt;Use the Factory Method pattern when&lt;br&gt;
a class can’t anticipate the class of objects it must create.&lt;br&gt;
A class wants its subclasses to specify the objects it creates.&lt;br&gt;
A classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate&lt;br&gt;
This design pattern is applied when a class needs to delegate the responsibility of object creation to its subclasses, allowing for flexibility, extensibility, and localized knowledge of which helper subclass is the delegate. It’s a powerful design pattern for scenarios where the exact type of objects to be created is determined at runtime or when different subclasses need to specify the types of objects they create.&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%2F0zgbifyk1mx96rd2ohfe.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%2F0zgbifyk1mx96rd2ohfe.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s end here for today and next time we’ll talk about behavioural pattern and it’s containing patterns
&lt;/h2&gt;

</description>
      <category>systemdesign</category>
      <category>designpatterns</category>
      <category>softwareengineering</category>
      <category>oop</category>
    </item>
    <item>
      <title>How to send data (state and props) between unrelated components in react</title>
      <dc:creator>kimbi619</dc:creator>
      <pubDate>Mon, 19 Apr 2021 04:12:49 +0000</pubDate>
      <link>https://dev.to/kimbi619/how-to-send-data-state-and-props-between-unrelated-components-in-react-51a1</link>
      <guid>https://dev.to/kimbi619/how-to-send-data-state-and-props-between-unrelated-components-in-react-51a1</guid>
      <description>&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%2F5c9ufxued13c6z2lbr3h.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%2F5c9ufxued13c6z2lbr3h.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
If you are new to react, you may have heard that data only flows in one direction as illustrated by the image above. To pass data from a lower level component to its parent or one of it's ancestors, you use something called &lt;a href="https://reactjs.org/docs/lifting-state-up.html" rel="noopener noreferrer"&gt;lifting up state&lt;/a&gt;, where data is being moved up to higher components having same parents and passing it down as props.&lt;br&gt;
In React, a state is always owned by one component. Any changes made by this state can only affect the components below it, i.e. its children. Changing state on a component will never affect its parent or its siblings, only the children will be affected. This is the main reason that the state is often moved up in the component tree so that it can be shared between the components that need to access it. However, to have a state affect directly an unrelated component was hard until the &lt;a href="https://reactjs.org/docs/context.html" rel="noopener noreferrer"&gt;useContext Hook&lt;/a&gt; was added to react.&lt;/p&gt;

&lt;p&gt;Suppose from the image you have an event listener on the component &lt;strong&gt;C&lt;/strong&gt; and you want it to cause a action on &lt;strong&gt;A&lt;/strong&gt; as illustrated above without having to send data to the database and getting that data from there. The answer to your problem is the use context hook in React. I will use the example on a book app I was creating for a library to explain this&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import React, {createContext, useState} from 'react'

export const BookHoldContext = createContext();

export const BookHoldProvider = (props)=&amp;gt;{
    const [clickedBook, setClickedBook] = useState(null);



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

&lt;/div&gt;

&lt;p&gt;Declaring using the useState method in react, you can create the data that you want to pass to the different components after importing the createContext method in react as in the first line. I have initially set it to &lt;code&gt;null&lt;/code&gt;, so that every time an event happens on it you get to set the data to what you currently want to get. Now to return this context, you use the context.Provider as below and pass the state as props in the value, except they are not especially props but return values.&lt;br&gt;
This is still within the provider function declared above&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

return(
        &amp;lt;BookHoldContext.Provider value={[clickedBook, setClickedBook]}&amp;gt;
            {props.children}
        &amp;lt;/BookHoldContext.Provider&amp;gt;
    )


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

&lt;/div&gt;

&lt;p&gt;Now to actually consume this context, you need to go to their common parent component and wrap the component  you need to provide access to with the Provider tag, after importing it of course &lt;code&gt;import { BookHoldProvider } from './BookHoldContext'&lt;/code&gt;&lt;br&gt;
in my case I need to share it between the book item and the book detail&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

return(
        &amp;lt;div id="book"&amp;gt;
            &amp;lt;BookHoldProvider&amp;gt;
            &amp;lt;div className="container"&amp;gt;
                &amp;lt;ul className="bookItem"&amp;gt;
                    {
                    AllBooks.map((book)=&amp;gt;(
                        &amp;lt;li key={book.isbn} &amp;gt;&amp;lt;Book book={book} 
                         showDetail={showDetail} /&amp;gt;&amp;lt;/li&amp;gt;
                    ))}
                &amp;lt;/ul&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;BookDetail showDetail = {showDetail}/&amp;gt;
            &amp;lt;/BookHoldProvider&amp;gt;
        &amp;lt;/div&amp;gt;
    )


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

&lt;/div&gt;

&lt;p&gt;Finally, on the function you where actually suppose to put that state on, you can import the created context and the useContext method inbuild in React&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import {useContext} from 'react';
import {BookHoldContext} from './BookHoldContext';


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

function BookDetail(){

    const [clickedBook, setClickedBook] = 
    useContext(BookHoldContext);
    return (
        &amp;lt;div className='bookToLoan' &amp;gt;
         {console.log(clickedBook)}
        &amp;lt;/div&amp;gt;
    )
}


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

&lt;/div&gt;

&lt;p&gt;Inside your component, you can call those values (useState hook) you passed in the context Provider and the data can be used. 🤗&lt;/p&gt;

&lt;p&gt;This is actually my first post here guys, I hope it helps someone&lt;/p&gt;

</description>
      <category>react</category>
      <category>usecontext</category>
      <category>hooks</category>
      <category>states</category>
    </item>
    <item>
      <title>Hello guys... I'm new here</title>
      <dc:creator>kimbi619</dc:creator>
      <pubDate>Mon, 12 Apr 2021 05:40:30 +0000</pubDate>
      <link>https://dev.to/kimbi619/hello-guys-i-m-new-here-mg2</link>
      <guid>https://dev.to/kimbi619/hello-guys-i-m-new-here-mg2</guid>
      <description>&lt;p&gt;Where is my room😁. Can't wait to meet the whole family🙃&lt;/p&gt;

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