<?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>Forem: jzfrank</title>
    <description>The latest articles on Forem by jzfrank (@jzfrank).</description>
    <link>https://forem.com/jzfrank</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%2F973742%2Fdf19de14-8dc0-4ad1-be72-a2c810748136.png</url>
      <title>Forem: jzfrank</title>
      <link>https://forem.com/jzfrank</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jzfrank"/>
    <language>en</language>
    <item>
      <title>HFDP(13) - Patterns in the real world (a review and a summary)</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Mon, 10 Jun 2024 08:06:56 +0000</pubDate>
      <link>https://forem.com/jzfrank/hfdp13-patterns-in-the-real-world-a-review-and-a-summary-1i0f</link>
      <guid>https://forem.com/jzfrank/hfdp13-patterns-in-the-real-world-a-review-and-a-summary-1i0f</guid>
      <description>&lt;p&gt;What is a pattern? Simply put, a pattern is a solution to a problem in a context. Note the context should be a recurring situation. Patterns are a collection of wisdom to solve problems. &lt;/p&gt;

&lt;h2&gt;
  
  
  Review
&lt;/h2&gt;

&lt;p&gt;Let's take a brief review of what we have learnt so far: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Decorator: wraps an object to provide new behavior&lt;/li&gt;
&lt;li&gt;State: encapsulates state-based behaviors and uses delegation to switch between behaviors. &lt;/li&gt;
&lt;li&gt;Iterator: provides a way to traverse a collection of objects without exposing its implementation. &lt;/li&gt;
&lt;li&gt;Facade: simplifies the interface of a set of classes. &lt;/li&gt;
&lt;li&gt;Strategy: encapsulates interchangeable behaviors and uses delegation to decide which one to use. &lt;/li&gt;
&lt;li&gt;Proxy: wraps an object to control access to it. &lt;/li&gt;
&lt;li&gt;Factory method: allows a client to create families of objects without specifying their concrete classes. &lt;/li&gt;
&lt;li&gt;Adapter: wraps an object and provides a different interface to it. &lt;/li&gt;
&lt;li&gt;Observer: allows objects to be notifies when state changes. &lt;/li&gt;
&lt;li&gt;Template method: Subclasses decide how to implement steps in an algorithm. &lt;/li&gt;
&lt;li&gt;Composite: Clients treat collections of objects and individual objects uniformly. &lt;/li&gt;
&lt;li&gt;Singleton: ensures one and only one object is created. &lt;/li&gt;
&lt;li&gt;Abstract factory: allows a client to create families of objects without specifying their concrete classes. &lt;/li&gt;
&lt;li&gt;Command: encapsulates a request as an object. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are more patterns for sure, but they are probably the most popular ones. &lt;/p&gt;

&lt;h2&gt;
  
  
  Category of Patterns
&lt;/h2&gt;

&lt;p&gt;There are many ways to classify patterns. Understanding the categories help you memorize them and communicate them better. &lt;/p&gt;

&lt;p&gt;One way is to partition patterns into creational, behavioral, structural pattern. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creational Pattern: involves object instantiation. Provides a way to decouple a client from the object it needs to instantiate. &lt;/li&gt;
&lt;li&gt;Behavioral Pattern: is concerned with how classes and objects interact and distribute responsibilities. &lt;/li&gt;
&lt;li&gt;Structural Pattern: lets you compose classes or objects into larger structures. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frd849hye9loiuqtrb8bb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frd849hye9loiuqtrb8bb.png" alt="creational-behavioral-structural" width="800" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another way is to classify them into class patterns and object patterns. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class Patterns describe how relationships between classes are defined via inheritance. Relationships in class patterns are established at compile time.&lt;/li&gt;
&lt;li&gt;Object Patterns describe relationships between objects and are primarily defined by composition. Relationships in object patterns are typically created at runtime and are more dynamic and flexible.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd2gyim46oohj9vjx6hlp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd2gyim46oohj9vjx6hlp.png" alt="class-object-patterns" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Remarks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Do not use patterns just to use patterns. Always prefer simplicity (KISS: keep it simple). If a problem could be solved without using patterns, prefer easier solution. Only use patterns whenever you see benefits (e.g. You see a practical change might happen, which could be solved by using patterns). &lt;/li&gt;
&lt;li&gt;Refactoring is usually patterns time. e.g. Many conditional statements may hint for State pattern. &lt;/li&gt;
&lt;li&gt;Patterns are a common vocabulary that accelerate communication among developers. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Anti-patterns
&lt;/h2&gt;

&lt;p&gt;Anti-patterns tell you a bad solution to a problem. Why it could be tempting. And what should be the right direction. &lt;/p&gt;

&lt;p&gt;See &lt;a href="https://sourcemaking.com/antipatterns"&gt;anti-patterns&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1mo8jtwe4eoc94oe4t4s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1mo8jtwe4eoc94oe4t4s.png" alt="anti-patterns" width="714" height="1508"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>HFDP(12) - Compound Pattern</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Wed, 29 May 2024 16:21:30 +0000</pubDate>
      <link>https://forem.com/jzfrank/hfdp12-compound-pattern-2e2b</link>
      <guid>https://forem.com/jzfrank/hfdp12-compound-pattern-2e2b</guid>
      <description>&lt;p&gt;Compound Pattern is to combine two or more patterns to solve a general problem. One of the most famous compound pattern is the MVC (model view controller) pattern. &lt;/p&gt;

&lt;p&gt;MVC involves Model, View, and Controller. When user touch a button, it will invoke controller to do certain things. The controller then invoke the model to modify its state. Finally, the model will notify the view that something changes. The view will be rendered accordingly. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgugmw15q1becdt4xk0kv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgugmw15q1becdt4xk0kv.png" alt="MVC" width="800" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Learning MVC from top down is a bit involving. However, learning it from bottom up is very simple. MVC is nothing but a combination of patterns. &lt;/p&gt;

&lt;p&gt;The controller and the view are using the &lt;code&gt;Strategy pattern&lt;/code&gt;. The view does not care the concrete behavior, it just invokes the controller. A concrete controller is just an implementation of an interface and could be easily replaced by another implementation. &lt;/p&gt;

&lt;p&gt;The model and the view are using the &lt;code&gt;Observer pattern&lt;/code&gt;. The model is the Observable and the view is the Observer. The model could notify the subscribed view the changes of its status. The observer view will update the view accordingly. &lt;/p&gt;

&lt;p&gt;The view itself is using the &lt;code&gt;Composite pattern&lt;/code&gt;. Consider the relationship between a window and a button. They are both visual elements but have an inclusive relation. A view could be a standalone or could contain other views. &lt;/p&gt;

&lt;p&gt;Sometimes we want to reuse a controller. Often we need to use Adapter pattern to adapt the interface. &lt;/p&gt;

&lt;p&gt;MVC pattern is so useful that it gets adapted and used in many popular frameworks. In the web world, a thin client approach is where the model, most of view, and the controller all reside in the server, while the browser renders the view. Single Page Application approach is all the model, view and controller reside in the browser. Most frameworks lie in between the two extremes. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>HFDP(11) - Proxy Pattern</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Tue, 28 May 2024 09:37:39 +0000</pubDate>
      <link>https://forem.com/jzfrank/hfdp11-proxy-pattern-4ef8</link>
      <guid>https://forem.com/jzfrank/hfdp11-proxy-pattern-4ef8</guid>
      <description>&lt;p&gt;Proxy manages and controls access. Proxy is a stand in for a real object. Proxy pattern has a lot of variations. &lt;/p&gt;

&lt;p&gt;For example, if we want to call a method of an object living remotely in another JVM, we need to make use of the Remote Proxy. In java, we could achieve this by using &lt;code&gt;rmi&lt;/code&gt; technology. Basically, the client calls a stub that implements the same Remote interface as the real subject. The stub then forwards the request to the skeleton living in the JVM, which then calls the real subject and forwards back returned value. Through the time, the client thinks it is accessing the real subject, which it is not doing this directly. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftn9k3g47fiykbgu11lcg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftn9k3g47fiykbgu11lcg.png" alt="Remote Proxy" width="800" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another well-known example is the Virtual Proxy. It is used for wrapping an expensive object like an image fetched from a network. Let's say you want to display an image on screen. Instead of fetching the image and manages the waiting yourself, you could delegate the task to a virtual proxy. It will fire a thread to fetch the image, and renders waiting texts while waiting. In this manner, you reduced the coupling in code. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi9uwtxohfcm59muk5xb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi9uwtxohfcm59muk5xb.png" alt="Virtual Proxy" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We may also need to manage access, which brings the Protection Proxy. It wraps an object and decides if the client could access certain methods of it. In Java it is implemented via reflection. e.g.&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="nc"&gt;Person&lt;/span&gt; &lt;span class="nf"&gt;getOwnerProxy&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;person&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="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Proxy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newProxyInstance&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getClass&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getClassLoader&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
    &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getClass&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getInterfaces&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;OwnerIncovationHandler&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&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;where &lt;code&gt;OwnerIncovationHandler&lt;/code&gt; implements &lt;code&gt;InvocationHandler&lt;/code&gt;. Its method signature is &lt;code&gt;Object invoke(Object proxy, Method method, Object[] args)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;We've seen a number of patterns that serve as wrapper. They look similar but serves different purposes: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Decorator Pattern: wrap an object add behaviors&lt;/li&gt;
&lt;li&gt;Facade Pattern: wrap possible many objects and simplify interfaces&lt;/li&gt;
&lt;li&gt;Adapter Pattern: wraps an object and implements another interface&lt;/li&gt;
&lt;li&gt;Proxy Pattern: wraps an object and controls access. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Proxy pattern has many variations: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Firewall Proxy (control access to network recourses) -&amp;gt; e.g. corporate firewall system. &lt;/li&gt;
&lt;li&gt;Smart Reference Proxy (provide additional actions when a subject is referenced e.g. count)&lt;/li&gt;
&lt;li&gt;Caching Proxy (temp store expensive resources) -&amp;gt; web server proxies and content management and publishing systems. &lt;/li&gt;
&lt;li&gt;Synchronization Proxy (provides safe access to a subject from multiple threads) &lt;/li&gt;
&lt;li&gt;Complexity Hiding Proxy (pretty much like Facade) &lt;/li&gt;
&lt;li&gt;Copy-on-Write Proxy (lazy copying, variant of Virtual Proxy)&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Set up a local mysql server on Mac with prisma</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Sat, 21 Oct 2023 14:00:22 +0000</pubDate>
      <link>https://forem.com/jzfrank/set-up-a-local-mysql-server-on-mac-with-prisma-120a</link>
      <guid>https://forem.com/jzfrank/set-up-a-local-mysql-server-on-mac-with-prisma-120a</guid>
      <description>&lt;p&gt;mysql is one of the most popular dialects of SQL. And prisma is an ORM tool that helps developer interact with database safer and better. &lt;/p&gt;

&lt;p&gt;In this post, we will discuss 1. how to set up a local mysql server 2. how to use it with prisma &lt;/p&gt;

&lt;h2&gt;
  
  
  Set up a local mysql server
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Download mysql
&lt;/h3&gt;

&lt;p&gt;Go to mysql website and choose downloads &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oYSGjR2F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x78qqa7xvcwhityokbc9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oYSGjR2F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x78qqa7xvcwhityokbc9.png" alt="Image description" width="800" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TEkJxlni--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5dhb3crfai1swfnsgzur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TEkJxlni--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5dhb3crfai1swfnsgzur.png" alt="Image description" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose community version &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VeETBvdE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpgnmb8bi4qjdbugdzag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VeETBvdE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpgnmb8bi4qjdbugdzag.png" alt="Image description" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose community server&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lHkP2o1h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jzlccpb8fdm9e93js8y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lHkP2o1h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jzlccpb8fdm9e93js8y.png" alt="Image description" width="800" height="631"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;download the version matching your Operation system &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vyY2za93--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aols4ze8p5khyyyo97d0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vyY2za93--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aols4ze8p5khyyyo97d0.png" alt="Image description" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;code&gt;No thanks, just start my downloads&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Install mysql
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3rQDchTD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ya4dvy24o7p83zs51nx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3rQDchTD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ya4dvy24o7p83zs51nx.png" alt="Image description" width="800" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VN_Eh4JV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8btsucd19la0zxjio6g0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VN_Eh4JV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8btsucd19la0zxjio6g0.png" alt="Image description" width="800" height="573"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PHt0arZQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xyb8m25hf8stq8ndk24l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PHt0arZQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xyb8m25hf8stq8ndk24l.png" alt="Image description" width="800" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6Jjblby---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2s218g8rf3oztrsidl5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6Jjblby---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2s218g8rf3oztrsidl5.png" alt="Image description" width="800" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1cOTIC7Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hiics7wpb6dtfpw6tuvl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1cOTIC7Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hiics7wpb6dtfpw6tuvl.png" alt="Image description" width="800" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sgMIDDMI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvavkb39gko42pjyc5dx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sgMIDDMI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvavkb39gko42pjyc5dx.png" alt="Image description" width="800" height="582"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a new Database
&lt;/h3&gt;

&lt;p&gt;Finish install guide. &lt;/p&gt;

&lt;p&gt;Now, open terminal and type&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;hit enter, you should see: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kj1zzgiy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3nneurm49rixxnrmgih.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kj1zzgiy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3nneurm49rixxnrmgih.png" alt="Image description" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, create a database with commands &lt;code&gt;CREATE DATABASES&lt;/code&gt;, here, we use &lt;code&gt;myFirstDB&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r_GoktIk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0xnuxzisismcbiw6aqm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r_GoktIk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0xnuxzisismcbiw6aqm.png" alt="Image description" width="530" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check if database is created successfully: &lt;code&gt;SHOW DATABASES&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ce3iEIxU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nfc0gqfay49iigsufcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ce3iEIxU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nfc0gqfay49iigsufcw.png" alt="Image description" width="434" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have successfully created the database, it's time to connect to it with prisma &lt;/p&gt;

&lt;h2&gt;
  
  
  Connect to DB with prisma
&lt;/h2&gt;

&lt;p&gt;I assume you have already installed prisma in your project. If not, go to &lt;a href="https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/relational-databases-typescript-mysql"&gt;setup-prisma&lt;/a&gt; and set it up. &lt;/p&gt;

&lt;p&gt;Now, what remains is to connect to our local database. &lt;br&gt;
mysql connection string should be of format: &lt;br&gt;
&lt;code&gt;mysql://USER:PASSWORD@HOST:PORT/DATABASE&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3306 is the default port. In our case, we don't have a password, we are using &lt;code&gt;root&lt;/code&gt;, connect to db &lt;code&gt;myFirstDB&lt;/code&gt;. So the connection string is simply &lt;code&gt;mysql://root@localhost:3306/myFirstDB&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In schema, prisma, for datasource, use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;.env&lt;/code&gt; file, add&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATABASE_URL="mysql://root@localhost:3306/myFirstDB" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you are good to go! To check if it actually works, open the database with sql db visualization tools like &lt;code&gt;Beekeeper Studio&lt;/code&gt;: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nRt8JelV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hrk0fuybua86hwwneo6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nRt8JelV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hrk0fuybua86hwwneo6.png" alt="Image description" width="800" height="344"&gt;&lt;/a&gt;&lt;br&gt;
click &lt;code&gt;import from url&lt;/code&gt; and &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G9utFqF7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rfsihkxy52eex7hr3cy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G9utFqF7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rfsihkxy52eex7hr3cy.png" alt="Image description" width="800" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;connect&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ryDsjCeC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93c6kchx7zwx0hv479sw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ryDsjCeC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93c6kchx7zwx0hv479sw.png" alt="Image description" width="800" height="943"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you see no table, which is expected. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VcnyoTJn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2t102zcrwutlrnvflqr6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VcnyoTJn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2t102zcrwutlrnvflqr6.png" alt="Image description" width="800" height="598"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To test, we add a dummy schema to &lt;code&gt;schema.prisma&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;model User {
  id   String @id @default(cuid())
  name String
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx prisma migrate dev --name init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in command line, this should generate db schema for you.&lt;/p&gt;

&lt;p&gt;Check &lt;code&gt;Beekeeper studio&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VQvp8hSy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evjuh526j7i7zc4hb1ta.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VQvp8hSy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evjuh526j7i7zc4hb1ta.png" alt="Image description" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have successfully initialized the local database with prisma! &lt;/p&gt;

&lt;p&gt;That's all for today, happy hacking! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Set up data science development: from zero to hero</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Thu, 22 Jun 2023 12:03:19 +0000</pubDate>
      <link>https://forem.com/jzfrank/set-up-data-science-development-from-zero-to-hero-4eff</link>
      <guid>https://forem.com/jzfrank/set-up-data-science-development-from-zero-to-hero-4eff</guid>
      <description>&lt;p&gt;When it comes to data science, python with jupyter-lab seems to be the go-to choice. &lt;/p&gt;

&lt;p&gt;However, when we start a new project, it always costs us half an hour or two to configure the right environment. Even just launching jupyter-lab and install our kernel to it. &lt;/p&gt;

&lt;p&gt;In this tutorial, I give a quick step-by-step guidance on setting up a new data science development environment. &lt;/p&gt;

&lt;p&gt;First, make sure &lt;code&gt;anaconda&lt;/code&gt; or &lt;code&gt;miniconda&lt;/code&gt; is installed. &lt;/p&gt;

&lt;p&gt;Then, create a new python environment using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;conda create &lt;span class="nt"&gt;-n&lt;/span&gt; myenv &lt;span class="nv"&gt;python&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3.9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you create a new environment called &lt;code&gt;myenv&lt;/code&gt; with python version 3.9. &lt;/p&gt;

&lt;p&gt;Next, activate the environment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;conda deactivate

&lt;span class="nv"&gt;$ &lt;/span&gt;conda activate myenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something like this in terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;myenv&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, install jupyter-lab&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;myenv&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$ &lt;/span&gt;conda &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; conda-forge jupyterlab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the last step, install current kernel to jupyterlab&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;myenv&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$ &lt;/span&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; ipykernel &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; myenv &lt;span class="nt"&gt;--display-name&lt;/span&gt; &lt;span class="s2"&gt;"myenv-display-name"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;myenv&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$ &lt;/span&gt;jupyter-lab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A new window of jupyter-lab will pop up. &lt;br&gt;
OK, you are all set! Let's do real data science! ;) &lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Set up a Local mysql Docker and View it using TablePlus</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Wed, 21 Jun 2023 18:50:50 +0000</pubDate>
      <link>https://forem.com/jzfrank/how-to-set-up-a-local-mysql-docker-and-view-it-using-tableplus-1b19</link>
      <guid>https://forem.com/jzfrank/how-to-set-up-a-local-mysql-docker-and-view-it-using-tableplus-1b19</guid>
      <description>&lt;p&gt;Create an empty folder. Open the folder. &lt;/p&gt;

&lt;p&gt;Create two files: &lt;code&gt;docker-compose.yml&lt;/code&gt; and &lt;code&gt;docker.env&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;docker-compose.yml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;version: "3.7"
services:
  db:
    image: mysql:8.0.33
    env_file: docker.env
    ports:
      - "3306:3306"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in &lt;code&gt;docker.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MYSQL_ROOT_PASSWORD=pass
MYSQL_DATABASE=mydb
DB_NAME=mydb
DB_HOST=db
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure docker is opened. Run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker compose up &lt;span class="nt"&gt;--build&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your mysql instance is running with connection string &lt;code&gt;mysql://root:pass@127.0.0.1:3306/mydb&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;To view the database, open TablePlus, create a new connection with above connection string. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Big Data for Engineers - Chapter 2: Lessons Learned from the past</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Sun, 05 Mar 2023 10:22:44 +0000</pubDate>
      <link>https://forem.com/jzfrank/big-data-for-engineers-chapter-2-lessons-learned-from-the-past-1c0a</link>
      <guid>https://forem.com/jzfrank/big-data-for-engineers-chapter-2-lessons-learned-from-the-past-1c0a</guid>
      <description>&lt;h2&gt;
  
  
  Data independence
&lt;/h2&gt;

&lt;p&gt;The fundamental socle on which modern data management is based (Edgar Codd 1950). &lt;/p&gt;

&lt;p&gt;Data independence means the independence of the &lt;strong&gt;logical view&lt;/strong&gt; on the data and &lt;strong&gt;physical&lt;/strong&gt; storage. &lt;/p&gt;

&lt;p&gt;A database management system stack is four-layer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A logical query language&lt;/li&gt;
&lt;li&gt;A logical model &lt;/li&gt;
&lt;li&gt;A physical compute layer that processes the query &lt;/li&gt;
&lt;li&gt;A physical storage layer where the data is physically stored&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the past two decades, the physical layer has changed: clusters with thousands of machines rather than a single machine. However, the look and feel of querying data remain the same to the end user. &lt;/p&gt;

&lt;h2&gt;
  
  
  Formal prerequisites
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Sets and relations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;set, inclusion: are trivial concepts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cartesian product&lt;/strong&gt;: AxB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;relation&lt;/strong&gt;: a relation R on a family of sets is a subset of their cartesian product. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;partial function&lt;/strong&gt;: A partial function p between two sets A and B is a &lt;strong&gt;relation&lt;/strong&gt; is a relation that does not associate any element of A to more than an element of B&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;function&lt;/strong&gt;: a partial function that is "injective" &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Sets commonly used:
&lt;/h3&gt;

&lt;p&gt;natural integers, relative integers, decimals, rational numbers, real numbers, a set of all values &lt;/p&gt;

&lt;h2&gt;
  
  
  Rational database management systems (RDBMS)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  main concepts
&lt;/h3&gt;

&lt;p&gt;RDBMS is based on a tabular data format. Its first class citizens:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;table: a collection of records &lt;/li&gt;
&lt;li&gt;attribute: a property that records can have&lt;/li&gt;
&lt;li&gt;row: a record in a collection. Also called: record, entity, document, item, business object&lt;/li&gt;
&lt;li&gt;primary key: attribute(s) tha uniquely identify a record&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  formalism behind relational model
&lt;/h3&gt;

&lt;p&gt;Tables can be defined formally (as purely mathematical objects) &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FZsX2yoz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2agw2qcq1kg7n2rveax.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FZsX2yoz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2agw2qcq1kg7n2rveax.png" alt="formalism of table" width="880" height="553"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Relational integrity
&lt;/h4&gt;

&lt;p&gt;A collection T fulfills relational integrity of all records have identical support. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wZpHuYsD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vx7sgeg2ygo33rnh8acn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wZpHuYsD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vx7sgeg2ygo33rnh8acn.png" alt="Relational integrity" width="880" height="951"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Domain integrity
&lt;/h4&gt;

&lt;p&gt;The values associated with each attribute should be restricted to a domain. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G9oqly-p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/smynx6kcjhovwdhz4o2c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G9oqly-p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/smynx6kcjhovwdhz4o2c.png" alt="Domain integrity" width="880" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YhFvI32p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ue4dxvj40n6tqvin0rz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YhFvI32p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ue4dxvj40n6tqvin0rz.png" alt="Not Domain integrity" width="880" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Atomic integrity
&lt;/h4&gt;

&lt;p&gt;values are only atomic values: the collections does not contain any nested collections or sets or lists or anything has a structure of its own. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4IWmxzg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czrt0i7av17diijq3uq3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4IWmxzg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czrt0i7av17diijq3uq3.png" alt="Atomic integrity " width="880" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8mEazrOL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rqv4r0q9hetjp4bfywhh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8mEazrOL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rqv4r0q9hetjp4bfywhh.png" alt="Not Atomic integrity" width="880" height="501"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If these constraints are relaxed, we enter the world of NoSQL databases: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--panf4alP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqit9bdwvodpbds01ffr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--panf4alP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqit9bdwvodpbds01ffr.png" alt="SQL vs NoSQL" width="880" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Relational Algebra
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AsyiPuRF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebg28xm8lnh08mfe0inp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AsyiPuRF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebg28xm8lnh08mfe0inp.png" alt="Relational Algebra" width="880" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Selection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oDD6BD4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj57yabt9zwn3lmtofd3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oDD6BD4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj57yabt9zwn3lmtofd3.png" alt="Selection" width="880" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Projection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VqRnbc0R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4e9ltlim1d1fsckojvqy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VqRnbc0R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4e9ltlim1d1fsckojvqy.png" alt="Projection" width="880" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Grouping&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--562hVNJX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hycax8l7phehbjiqj7me.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--562hVNJX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hycax8l7phehbjiqj7me.png" alt="Grouping" width="880" height="680"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Renaming&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Changes the name of a column&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M_VuXvba--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i6on62tib1hu80ftf91o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M_VuXvba--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i6on62tib1hu80ftf91o.png" alt="Renaming" width="880" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extended projections&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Compute values and assign results to a new column. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ol1Cj6dF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9u8i0a5wlnwq3cbf08dj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ol1Cj6dF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9u8i0a5wlnwq3cbf08dj.png" alt="Extended projections" width="880" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cartesian products&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LgLUwNJZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0xyfebce52esnj80ujj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LgLUwNJZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0xyfebce52esnj80ujj.png" alt="Cartesian products" width="880" height="676"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Joins&lt;/strong&gt;&lt;br&gt;
Join is a "filtered Cartesian proect" in which we only combine directly related tuples and omit all other non-matching pairs. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eH9PHtWO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2qh5ettnhn7zav8s9fe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eH9PHtWO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2qh5ettnhn7zav8s9fe.png" alt="Joins" width="880" height="207"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6COkO7Xi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcb3scudevaivdlhgw6v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6COkO7Xi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcb3scudevaivdlhgw6v.png" alt="Joins" width="880" height="510"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Normal Forms
&lt;/h2&gt;

&lt;p&gt;Anomalies might occur in poorly designed databases. To avoid anomalies, best practice is to follow normal forms. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First normal form&lt;/strong&gt;: atomic integrity &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KSb-BWB2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jfj2hxxge2qsop7zlwl7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KSb-BWB2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jfj2hxxge2qsop7zlwl7.png" alt="not atomic integrity" width="880" height="511"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XGddu1e7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jdh5b8tq8lukqemia1sw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XGddu1e7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jdh5b8tq8lukqemia1sw.png" alt="atomic integrity" width="880" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second normal form&lt;/strong&gt;: each column in a record contains information on the entire record. A table should be only about one type of thing. Each non key field must be about the same thing as the primary key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N03Lv_E1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/00totnfjmveefmhwsqzs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N03Lv_E1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/00totnfjmveefmhwsqzs.png" alt="Not Second normal form" width="880" height="526"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l8tLVHwf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mrr37rlh58u4o7228axf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l8tLVHwf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mrr37rlh58u4o7228axf.png" alt="Second normal form" width="880" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third normal form&lt;/strong&gt;: forbids functional dependency on anything else than the primary key&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hvG-TiOn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/87sb95yjxvanzyfb08mv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hvG-TiOn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/87sb95yjxvanzyfb08mv.png" alt="Not Third normal form" width="880" height="778"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vr1tOqnd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ul8nfzmxgwljpz9y59r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vr1tOqnd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ul8nfzmxgwljpz9y59r.png" alt="Third normal form" width="880" height="423"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  SQL language
&lt;/h2&gt;

&lt;p&gt;SQL is a declarative language. SQL is also a functional language (to some extent). &lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;century&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;cent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;num_captains&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;ships&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;captains&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ships&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;captain&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;century&lt;/span&gt;
&lt;span class="k"&gt;HAVING&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Internally: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7TYwXxXG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/88axglirw7yszzmkg0kx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7TYwXxXG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/88axglirw7yszzmkg0kx.png" alt="SQL internal" width="880" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Languages
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aa2SZ_Bp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrs3f8kkjavqqpye354r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aa2SZ_Bp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrs3f8kkjavqqpye354r.png" alt="bigger picture" width="880" height="510"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Transactions
&lt;/h2&gt;

&lt;p&gt;ACID: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Atomicity: either an update is applied completely, or not at all&lt;/li&gt;
&lt;li&gt;Consistency: Properties of database stays the same&lt;/li&gt;
&lt;li&gt;Isolation: the system "feels like" the user is the only one using the system, however in fact thousands are using concurrently. &lt;/li&gt;
&lt;li&gt;Durability: all data written to database is durably stored and will not be lost (e.g. electricity shortage or a disk crash) &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Scaling up and out
&lt;/h2&gt;

&lt;p&gt;If we have a lot of rows: object storage, column storage, distributed file systems, massive parallel processing.&lt;/p&gt;

&lt;p&gt;If we have a lot of columns: column storage.&lt;/p&gt;

&lt;p&gt;If we have a lot of nesting: syntax, data models, document stores, querying. &lt;/p&gt;

&lt;p&gt;So, if you do not fully understand normal forms, 3 integrities, and ACID. It is OK for this course, we will very soon break these conventions and enter the Big Data world. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>HFDP(10) - State Pattern</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Mon, 27 Feb 2023 21:40:28 +0000</pubDate>
      <link>https://forem.com/jzfrank/hfdp10-state-pattern-1ggd</link>
      <guid>https://forem.com/jzfrank/hfdp10-state-pattern-1ggd</guid>
      <description>&lt;p&gt;Suppose you are to maintain a &lt;code&gt;gumballMachine&lt;/code&gt;, which takes quarters, gives gumball after turning the crank. How would you implement it? The gumball machine certainly behaves differently when in different states (no quarter, inserted one quarter, sold, sold out etc.). Well, we can certainly use if else clauses. However, if new functionalities might be added (for example, randomly generate a winner that gets two gumballs), we can already foresee the code will be messy to maintain. &lt;/p&gt;

&lt;p&gt;A natural solution to problem like this, where the object behaves differently under different context, could be the State Pattern. &lt;/p&gt;

&lt;h2&gt;
  
  
  Formal Definition
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;State Pattern&lt;/strong&gt; allows an object to alter its behavior when its internal state changes. The object will appear to change its class.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We say "appear" because the object cannot change its class after it is initialized. However, it does appears to change its class, as it will behave differently under different context. This is because its state has changed. The way we implement that is to maintain &lt;code&gt;state&lt;/code&gt; inside the object, and switch it whenever needed. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fontdtjj8d7f6hjfw8yza.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fontdtjj8d7f6hjfw8yza.png" alt="State Pattern" width="800" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our &lt;code&gt;Context&lt;/code&gt; object will have an internal member that maintains &lt;code&gt;State&lt;/code&gt;. When &lt;code&gt;request()&lt;/code&gt; is called, we are calling &lt;code&gt;state.handle()&lt;/code&gt; under the hood. The magic is the &lt;code&gt;State&lt;/code&gt; interface. We will have concrete implementation of this interface, and implement &lt;code&gt;handle()&lt;/code&gt; differently under different states. &lt;/p&gt;

&lt;p&gt;As a side note, we may see similarity between State Pattern and Strategy Pattern. Both of them delegate execution to another composition class (remember our &lt;code&gt;Duck&lt;/code&gt; app?). However, the State Pattern is meant for different behaviors of an object under different states. The strategy pattern, in my humber opinion, is like saving us from implementing tons of classes that differ only by a set of behaviors (Don't get me wrong, all of them have the behaviors. They just behave differently). &lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>Big Data for Engineers - Chapter 1: Introduction</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Fri, 24 Feb 2023 16:00:17 +0000</pubDate>
      <link>https://forem.com/jzfrank/big-data-for-engineers-chapter-1-introduction-17jb</link>
      <guid>https://forem.com/jzfrank/big-data-for-engineers-chapter-1-introduction-17jb</guid>
      <description>&lt;p&gt;Magnitude is an interesting concept. We have a good feeling about measuring real world objects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Our height -&amp;gt; meter&lt;/li&gt;
&lt;li&gt;Driving Cars -&amp;gt; kilometers &lt;/li&gt;
&lt;li&gt;Size of Earth -&amp;gt; megameters&lt;/li&gt;
&lt;li&gt;Distance of Earth to Sun -&amp;gt; gigameters &lt;/li&gt;
&lt;li&gt;Distance of Jupyter to Sun -&amp;gt; terameters &lt;/li&gt;
&lt;li&gt;Entire Solar System -&amp;gt; petameters 
...... &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, we seem to fail to appreciate the magnitude of data: we take 1GB, 1TB for granted, without thinking what a large number that is. &lt;br&gt;
In terms of bytes, approximately: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;kB = 1,000 B&lt;/li&gt;
&lt;li&gt;MB = 1,000,000 B&lt;/li&gt;
&lt;li&gt;GB = 1,000,000,000 B&lt;/li&gt;
&lt;li&gt;TB = 1,000,000,000,000 B&lt;/li&gt;
&lt;li&gt;PB = 1,000,000,000,000,000 B&lt;/li&gt;
&lt;li&gt;EB = 1,000,000,000,000,000,000 B&lt;/li&gt;
&lt;li&gt;ZB = 1,000,000,000,000,000,000,000 B&lt;/li&gt;
&lt;li&gt;YB = 1,000,000,000,000,000,000,000,000 B&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;kilobyte, megabyte, gigabyte, terabyte, petabyte, exabyte, zettabyte, yottabyte. Isn't that impressive? &lt;/p&gt;

&lt;p&gt;To understand the importance of learning big data, we discuss 3 V's. &lt;/p&gt;

&lt;h2&gt;
  
  
  3 Vs of big data
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Volume
&lt;/h3&gt;

&lt;p&gt;The volume of data stored is increasing exponentially. In 2021, it's around 100ZB. &lt;/p&gt;

&lt;h3&gt;
  
  
  Variety
&lt;/h3&gt;

&lt;p&gt;Data exists in various forms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;trees (JSON, XML)&lt;/li&gt;
&lt;li&gt;unstructured (text, pictures, audio, video) &lt;/li&gt;
&lt;li&gt;cubes &lt;/li&gt;
&lt;li&gt;graphs (neo4j, Oracle PGX) &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Velocity
&lt;/h3&gt;

&lt;p&gt;How fast can we process data? Three factors affect the velocity: capacity, thoughput, latency. &lt;/p&gt;

&lt;p&gt;From 1956 to 2021, capacity has increased by a factor of 200,000,000,000, throughput by 10,000, latency (decreases) by 150. So the throughput and latency cannot catch up with the capacity. &lt;/p&gt;

&lt;p&gt;However, if we do parallel or batch processing, we may reduce that gap. &lt;/p&gt;

</description>
      <category>cryptocurrency</category>
      <category>crypto</category>
      <category>bitcoin</category>
    </item>
    <item>
      <title>HFDP(9) - Iterator Pattern and Composite Pattern</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Tue, 21 Feb 2023 09:36:27 +0000</pubDate>
      <link>https://forem.com/jzfrank/hfdp9-iterator-pattern-and-composite-pattern-5a25</link>
      <guid>https://forem.com/jzfrank/hfdp9-iterator-pattern-and-composite-pattern-5a25</guid>
      <description>&lt;p&gt;In this post we discuss two patterns: the Iterator pattern and the Composite Pattern. &lt;/p&gt;

&lt;h2&gt;
  
  
  Iterator Pattern
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Intro
&lt;/h3&gt;

&lt;p&gt;Suppose you are merging two restaurants. Each has their own menus and implemented differently. Say one uses &lt;code&gt;ArrayList&lt;/code&gt;, another uses &lt;code&gt;Array&lt;/code&gt;. How would you iterate over the menus? We may of course do a type check and treat them differently. However, this will expose the internal representation and seems not so generic. Do we have a better approach? The Iterator Pattern comes to our rescue. &lt;/p&gt;

&lt;p&gt;Instead of exposing the internal representation, we may define a method called &lt;code&gt;createIterator()&lt;/code&gt; that returns an &lt;code&gt;Iterator&lt;/code&gt;. In such manner, we could use the returned &lt;code&gt;Iterator&lt;/code&gt; interface &lt;code&gt;hasNext()&lt;/code&gt;, &lt;code&gt;next()&lt;/code&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Formal Definition
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;Iterator Pattern&lt;/strong&gt; provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UhZBM_6i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zmupvhftf65u934uepq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UhZBM_6i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zmupvhftf65u934uepq.png" alt="Iterator Pattern" width="880" height="603"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is, the client should deal with two interfaces: the &lt;code&gt;Aggregate&lt;/code&gt; and the &lt;code&gt;Iterator&lt;/code&gt;. And the &lt;code&gt;Aggregate&lt;/code&gt; should have a method called &lt;code&gt;createIterator&lt;/code&gt; which returns an &lt;code&gt;Iterator&lt;/code&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Composite Pattern
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Intro
&lt;/h3&gt;

&lt;p&gt;Suppose now you are merging more restaurants, whose menus have submenus. Now we have recursive structure here. Instead of treating menu and menuItem separately, we may use Composite Pattern to treat them &lt;em&gt;transparently/uniformly&lt;/em&gt;. We may define an interface &lt;code&gt;MenuComponent&lt;/code&gt; and let &lt;code&gt;Menu&lt;/code&gt; and &lt;code&gt;MenuItem&lt;/code&gt; implement that. &lt;/p&gt;

&lt;h3&gt;
  
  
  Formal Definition
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;Composite Pattern&lt;/strong&gt; allows you to compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HEh2nQ6O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4zqv4cc8z8pdikanmow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HEh2nQ6O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4zqv4cc8z8pdikanmow.png" alt="Composite Pattern" width="880" height="722"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What's more, since our Composite often contain many subcomponents, we may implement a &lt;code&gt;createIterator()&lt;/code&gt; method. This is the connection between Iterator Pattern and Composite Pattern. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>HFDP(8) - Template Method Pattern</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Tue, 14 Feb 2023 14:22:56 +0000</pubDate>
      <link>https://forem.com/jzfrank/hfdp8-template-method-pattern-5252</link>
      <guid>https://forem.com/jzfrank/hfdp8-template-method-pattern-5252</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Many of us are living on caffein beverages. Some of us drink coffee, some of us drink tea. Check out the steps needed to make a coffee: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Boil some water&lt;/li&gt;
&lt;li&gt;Brew Coffee in boiling water&lt;/li&gt;
&lt;li&gt;Pour coffee in cup &lt;/li&gt;
&lt;li&gt;Add sugar and milk &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;and steps to make a tea:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Boil some water&lt;/li&gt;
&lt;li&gt;Brew tea in boiling water&lt;/li&gt;
&lt;li&gt;Pour tea in cup &lt;/li&gt;
&lt;li&gt;Add lemon &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We can already see there exists an underlying similar algorithm for the two processes, namely: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Boil water&lt;/li&gt;
&lt;li&gt;Brew&lt;/li&gt;
&lt;li&gt;Pour in cup&lt;/li&gt;
&lt;li&gt;Add condiments &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Of course, we may add different condiments to tea and coffee. That should be left for the subclass to implement. &lt;/p&gt;

&lt;p&gt;So yes, this is it! Abstract the steps into a template method (encapsulating algorithms), then leaving specific step(s) in the algorithm to the subclasses. This is the intuition for our Template Method Pattern &lt;/p&gt;

&lt;h2&gt;
  
  
  Definition
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The Template Method Pattern&lt;/strong&gt; defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method let's subclasses redefine certain steps of an algorithm without changing the algorithm's structure. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When we implement this, we usually declare the template method as &lt;code&gt;final&lt;/code&gt;, and to-be-implemented methods as &lt;code&gt;abstract&lt;/code&gt;. We also define one or many &lt;code&gt;hook&lt;/code&gt; method, which are optional for the subclasses to implement. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fj3uukdbukkhb2zxisu7k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fj3uukdbukkhb2zxisu7k.png" alt="Template Method Pattern" width="666" height="950"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Design Principle
&lt;/h2&gt;

&lt;p&gt;The Hollywood Principle &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don't call us, we'll call you. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This principle states that one should avoid the circular dependencies between up and low level components. -&amp;gt; Just let the high-level component controls the low-level components, but not the converse. &lt;/p&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;Template Method pattern is particularly useful in frameworks. &lt;/p&gt;

&lt;h3&gt;
  
  
  Java Arrays Sorting
&lt;/h3&gt;

&lt;p&gt;Say we have an array of self-defined classes &lt;code&gt;Duck&lt;/code&gt;, to use Sorting provided by Java, we need to make &lt;code&gt;Duck&lt;/code&gt; implement &lt;code&gt;Comparable&lt;/code&gt; interface and implement &lt;code&gt;compareTo&lt;/code&gt; method. &lt;/p&gt;

&lt;h3&gt;
  
  
  Swing JFrame
&lt;/h3&gt;

&lt;p&gt;JFrame's update algorithm calls &lt;code&gt;paint()&lt;/code&gt;, But by default &lt;code&gt;paint()&lt;/code&gt; does nothing. It is a hook and can(should) be overwritten. &lt;/p&gt;

</description>
      <category>vibecoding</category>
    </item>
    <item>
      <title>HFDP(7) - Adapter and Facade Pattern</title>
      <dc:creator>jzfrank</dc:creator>
      <pubDate>Sat, 21 Jan 2023 15:10:03 +0000</pubDate>
      <link>https://forem.com/jzfrank/hfdp7-adapter-and-facade-pattern-kn5</link>
      <guid>https://forem.com/jzfrank/hfdp7-adapter-and-facade-pattern-kn5</guid>
      <description>&lt;p&gt;In this post we will discuss two pattens: Adapter Pattern and Facade Pattern. Why we put them in the same post? Because their purpose is kinda similar: both "converting"  something unsuitable/complex into something suitable/simple. &lt;/p&gt;

&lt;h2&gt;
  
  
  Adapter Pattern
&lt;/h2&gt;

&lt;p&gt;Imagine you are on travel. You travel many countries: U.S., U.K., Switzerland, China etc. You realized that different areas are using different sockets. What do you do? You use adapters. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F2qgkcr8cnqq43o3p6ely.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F2qgkcr8cnqq43o3p6ely.png" alt="Adapter for Sockets" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is exactly the idea of Adapter Pattern. Say you were using the java's interface &lt;code&gt;Enumeration&lt;/code&gt;. However, as java gets updated in new versions, it has a new interface &lt;code&gt;Iterator&lt;/code&gt;. You want to use &lt;code&gt;Iterator&lt;/code&gt; object in your code, however, instead of changing everything, you want to keep old code as much as possible. What do you do? You write an adapter to adapt &lt;code&gt;Iterator&lt;/code&gt; to &lt;code&gt;Enumeration&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;An example of implementing:&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;IteratorEnumeration&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Enumeration&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; 
    &lt;span class="nc"&gt;Iterator&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;IteratorEnumeration&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Iterator&lt;/span&gt; &lt;span class="n"&gt;iterator&lt;/span&gt;&lt;span class="o"&gt;)&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;iterator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;iterator&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;boolean&lt;/span&gt; &lt;span class="nf"&gt;hasMoreElements&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;iterator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hasNext&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="nc"&gt;Object&lt;/span&gt; &lt;span class="nf"&gt;nextElement&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;iterator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Formal Definition
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;Adapter Pattern&lt;/strong&gt; converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ffx2azywc5vag45gd8ko0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ffx2azywc5vag45gd8ko0.png" alt="Adapter Pattern" width="800" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In fact, there are two kinds of adapter patterns: object adapter and class adapter. While the object adapter pattern achieves this by passing object, the class adapter pattern achieves this by multiple inheritance. &lt;/p&gt;

&lt;h2&gt;
  
  
  Facade Pattern
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F0rpb55af2z0ooa92vz45.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F0rpb55af2z0ooa92vz45.png" alt="the Facade" width="800" height="535"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine you are setting your personal home movie theater. You bought the equipments, you settled the locations, you connected the internet, you bought a popcorn machine, and you even bought Netflix. OK, everything seems cool. Let's sit down and enjoy our well-earned leisure of watching movie. Now what do you need to do? You need to 1) turn on the projector 2) close lights 3) turn on popcorn machine 4)  open netflix and search for target movie 5) set volume to medium (say 15) etc. ... Hey, why it is so complicated? What's worse, when we want to quit, we need to undo everything. Wouldn't it be nice if we have a remote controller that turns on everything once we hit "on" mode, turns off everything once we hit "off" mode. This will need the facade pattern, which tries to provide a simplified interface for a large and complex subsystem. The facade pattern provides intuitive interfaces and reduces coupling with the subsystems. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ffa0kov06tnv09awlmn3p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ffa0kov06tnv09awlmn3p.png" alt="movie theater all" width="800" height="552"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3ob9k487ofng5xvj0wl4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3ob9k487ofng5xvj0wl4.png" alt="manual steps" width="800" height="1016"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fg51banemykikfvk18jyx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fg51banemykikfvk18jyx.png" alt="movie theater with facade" width="800" height="1007"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Formal Definition
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;Facade Pattern&lt;/strong&gt; provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher- level interface that makes the subsystem easier to use.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fw4dxmmzwww3i5i08lyad.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fw4dxmmzwww3i5i08lyad.png" alt="Facade Pattern Diagram" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Design Principle
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Principle of Least Knowledge - talk only to your immediate friends.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Facade Pattern is a good illustration of this principle. No matter how complex the subsystem is, if the client code only talks to the simplified interface (the facade), things will become easier and coupling will be reduced. &lt;/p&gt;

&lt;p&gt;Using this principle, we should not call methods on returned objects. For example, &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fx2kwpkxavb6yuwie0fgc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fx2kwpkxavb6yuwie0fgc.png" alt="Principle of Least Knowledge" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now it comes to the end of this post. We have discussed adapter pattern and facade pattern. Further, we introduced principle of least knowledge in light of facade pattern. &lt;strong&gt;Adapter Pattern&lt;/strong&gt;: When we have two similar interfaces, we use Adapter Pattern if we want to use one pattern as another pattern. &lt;strong&gt;Facade Pattern&lt;/strong&gt;: When we have a overly complex subsystem while we want simplified interface, we use Facade Pattern. &lt;/p&gt;

&lt;p&gt;See you next post! &lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
