<?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: Edwin Zamora</title>
    <description>The latest articles on DEV Community by Edwin Zamora (@edzamo).</description>
    <link>https://dev.to/edzamo</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%2F1342021%2Ff6ec9688-dae0-4e61-bc4c-47aa51572069.jpeg</url>
      <title>DEV Community: Edwin Zamora</title>
      <link>https://dev.to/edzamo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/edzamo"/>
    <language>en</language>
    <item>
      <title>🧠 Demystifying the Factory Method Pattern with a Manabita Twist</title>
      <dc:creator>Edwin Zamora</dc:creator>
      <pubDate>Fri, 12 Sep 2025 23:25:21 +0000</pubDate>
      <link>https://dev.to/edzamo/demystifying-the-factory-method-pattern-with-a-manabita-twist-ne6</link>
      <guid>https://dev.to/edzamo/demystifying-the-factory-method-pattern-with-a-manabita-twist-ne6</guid>
      <description>&lt;p&gt;Hello, let's dive into the fascinating world of design patterns. We'll start with one of the most useful and simple ones to get started: the &lt;strong&gt;Factory Method&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Throughout this post, we'll look at the theory, a practical example, and best of all, we'll "ground" it with a 100% Ecuadorian use case.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Factory Method and How Does It Work?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Factory Method&lt;/strong&gt; is a creational design pattern that solves the problem of creating objects without specifying their concrete classes. Sound complicated? Not at all.&lt;/p&gt;

&lt;p&gt;Imagine you have a class that needs to create objects, but it doesn't know exactly &lt;em&gt;which&lt;/em&gt; ones it will create. It might depend on a configuration, parameters, or the environment. Instead of filling your code with &lt;code&gt;if-else&lt;/code&gt; or &lt;code&gt;switch&lt;/code&gt; statements to instantiate each object with &lt;code&gt;new&lt;/code&gt;, you delegate that responsibility to a special method: the &lt;strong&gt;factory method&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This gives us incredible flexibility, as the main code works with a common interface and doesn't care about the specific implementation of the object it receives.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Could I Use It? The Classic Example: A Payment System
&lt;/h2&gt;

&lt;p&gt;In our project, we have a perfect example that simulates a payment system.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The Product (&lt;code&gt;Payment&lt;/code&gt;):&lt;/strong&gt; First, we define an interface that establishes the contract. All payment methods must have a way to "make the payment".&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/main/java/ec/com/pattern/creational/factorymethod/payment/Payment.java&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;doPayment&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;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The Concrete Products (&lt;code&gt;CardPayment&lt;/code&gt;, &lt;code&gt;GooglePayment&lt;/code&gt;):&lt;/strong&gt; Next, we create the classes that implement that interface. Each one represents a specific type of payment.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/main/java/ec/com/pattern/creational/factorymethod/payment/CardPayment.java&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CardPayment&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;doPayment&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Making payment with Card"&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;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The Factory (&lt;code&gt;PaymentFactory&lt;/code&gt;):&lt;/strong&gt; Here's the magic. We create a class whose sole job is to create and return the correct object based on a parameter.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/main/java/ec/com/pattern/creational/factorymethod/payment/PaymentFactory.java&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentFactory&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt; &lt;span class="nf"&gt;buildPayment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TypePayment&lt;/span&gt; &lt;span class="n"&gt;typePayment&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;typePayment&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;CARD:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;CardPayment&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;GOOGLE:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;GooglePayment&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;PAYPAL:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaypalPayment&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"No such payment"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  🔹 Simple Explanation with a Real-World Example
&lt;/h3&gt;

&lt;p&gt;Imagine you work at a bank:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; The customer chooses to pay with a card, Google Pay, or PayPal.&lt;/li&gt;
&lt;li&gt; The factory (&lt;code&gt;PaymentFactory&lt;/code&gt;) receives that information (the &lt;code&gt;TypePayment&lt;/code&gt; enum).&lt;/li&gt;
&lt;li&gt; The factory creates the appropriate object:

&lt;ul&gt;
&lt;li&gt;  If it's &lt;code&gt;CARD&lt;/code&gt; → returns a &lt;code&gt;CardPayment&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  If it's &lt;code&gt;GOOGLE&lt;/code&gt; → returns a &lt;code&gt;GooglePayment&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  If it's &lt;code&gt;PAYPAL&lt;/code&gt; → returns a &lt;code&gt;PaypalPayment&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt; The system calls &lt;code&gt;doPayment()&lt;/code&gt; regardless of the payment type, because all classes implement the same &lt;code&gt;Payment&lt;/code&gt; interface.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  👉 In summary:
&lt;/h3&gt;

&lt;p&gt;This diagram shows a Factory pattern where a factory centralizes the creation of different payment types, using an &lt;code&gt;enum&lt;/code&gt; to decide which concrete class to instantiate.&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%2Fi7gbg4gfg1786aysgplh.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%2Fi7gbg4gfg1786aysgplh.png" alt=" " width="800" height="670"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adapting It "to the Local Style": A Seafood Restaurant in Manabí
&lt;/h2&gt;

&lt;p&gt;Now, let's get to our own thing! Let's forget about payments and technology for a moment and think about something that defines us: food.&lt;/p&gt;

&lt;p&gt;Imagine we're building the software for a seafood restaurant in Portoviejo. In Manabí, the same dish can have variations. For example, a "ceviche" can be made with fish, shrimp, or a mix. They are all ceviches, but they are prepared slightly differently.&lt;/p&gt;

&lt;p&gt;This is where the Factory Method shines.&lt;/p&gt;




&lt;h3&gt;
  
  
  💻 Example Source Code
&lt;/h3&gt;

&lt;p&gt;You can find all the code for this example in the project folder on GitHub:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://github.com/edzamo/software-engineering/tree/main/design-pattern/udemy-course/src/main/java/ec/com/pattern/creational/factorymethod/cevichemanabita" rel="noopener noreferrer"&gt; &lt;strong&gt;See the code for the Manabita Ceviche example&lt;/strong&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  File Structure (example)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
 ├─ Ceviche.java                # product interface
 ├─ CevicheType.java            # enum with types
 ├─ FishCeviche.java
 ├─ ShrimpCeviche.java
 ├─ MixedCeviche.java
 ├─ JipijapaCeviche.java
 └─ ManabitaRestaurantFactory.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fac5f028t9hbxq4lhs003.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%2Fac5f028t9hbxq4lhs003.png" alt=" " width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>designpatterns</category>
      <category>ecuador</category>
    </item>
    <item>
      <title>🧠 Desmitificando el Patrón Factory Method con un Toque Manabita</title>
      <dc:creator>Edwin Zamora</dc:creator>
      <pubDate>Fri, 12 Sep 2025 23:18:57 +0000</pubDate>
      <link>https://dev.to/edzamo/desmitificando-el-patron-factory-method-con-un-toque-manabita-1a67</link>
      <guid>https://dev.to/edzamo/desmitificando-el-patron-factory-method-con-un-toque-manabita-1a67</guid>
      <description>&lt;p&gt;¡Hola, vamos a sumergirnos en el fascinante mundo de los patrones de diseño. Empezaremos con uno de los más útiles y sencillos para iniciarse: el &lt;strong&gt;Factory Method&lt;/strong&gt; (Método de Fábrica).&lt;/p&gt;

&lt;p&gt;A lo largo de este post, veremos la teoría, un ejemplo práctico y, lo mejor de todo, lo "aterrizaremos" con un caso de uso 100% ecuatoriano.&lt;/p&gt;

&lt;h2&gt;
  
  
  ¿Qué es y cómo funciona el Factory Method?
&lt;/h2&gt;

&lt;p&gt;El &lt;strong&gt;Factory Method&lt;/strong&gt; es un patrón de diseño creacional que resuelve el problema de crear objetos sin especificar sus clases concretas. ¿Suena complicado? Para nada.&lt;/p&gt;

&lt;p&gt;Imagina que tienes una clase que necesita crear objetos, pero no sabe exactamente &lt;em&gt;cuáles&lt;/em&gt; creará. Dependerá de una configuración, de parámetros o del entorno. En lugar de llenar tu código con &lt;code&gt;if-else&lt;/code&gt; o &lt;code&gt;switch&lt;/code&gt; para instanciar cada objeto con &lt;code&gt;new&lt;/code&gt;, delegas esa responsabilidad a un método especial: el &lt;strong&gt;método de fábrica&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Esto nos da una flexibilidad increíble, ya que el código principal trabaja con una interfaz común y no le importa la implementación específica del objeto que recibe.&lt;/p&gt;

&lt;h2&gt;
  
  
  ¿Cómo lo podría usar? El Ejemplo Clásico: Un Sistema de Pagos
&lt;/h2&gt;

&lt;p&gt;En nuestro proyecto, tenemos un ejemplo perfecto que simula un sistema de pagos.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;El Producto (&lt;code&gt;Payment&lt;/code&gt;):&lt;/strong&gt; Primero, definimos una interfaz que establece el contrato. Todos los métodos de pago deben tener una forma de "hacer el pago".&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/main/java/ec/com/pattern/creational/factorymethod/payment/Payment.java&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;doPayment&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;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Los Productos Concretos (&lt;code&gt;CardPayment&lt;/code&gt;, &lt;code&gt;GooglePayment&lt;/code&gt;):&lt;/strong&gt; Luego, creamos las clases que implementan esa interfaz. Cada una representa un tipo de pago específico.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/main/java/ec/com/pattern/creational/factorymethod/payment/CardPayment.java&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CardPayment&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;doPayment&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Making payment with Card"&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;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;La Fábrica (&lt;code&gt;PaymentFactory&lt;/code&gt;):&lt;/strong&gt; Aquí está la magia. Creamos una clase cuyo único trabajo es crear y devolver el objeto correcto según un parámetro.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/main/java/ec/com/pattern/creational/factorymethod/payment/PaymentFactory.java&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentFactory&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt; &lt;span class="nf"&gt;buildPayment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TypePayment&lt;/span&gt; &lt;span class="n"&gt;typePayment&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;typePayment&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;CARD:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;CardPayment&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;GOOGLE:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;GooglePayment&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;PAYPAL:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaypalPayment&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"No such payment"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  🔹 Explicación simple con un ejemplo del mundo real
&lt;/h3&gt;

&lt;p&gt;Imagina que trabajas en un banco:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; El cliente elige pagar con tarjeta, Google Pay o PayPal.&lt;/li&gt;
&lt;li&gt; La fábrica (&lt;code&gt;PaymentFactory&lt;/code&gt;) recibe esa información (el &lt;code&gt;TypePayment&lt;/code&gt; enum).&lt;/li&gt;
&lt;li&gt; La fábrica crea el objeto apropiado:

&lt;ul&gt;
&lt;li&gt;  Si es &lt;code&gt;CARD&lt;/code&gt; → devuelve un &lt;code&gt;CardPayment&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  Si es &lt;code&gt;GOOGLE&lt;/code&gt; → devuelve un &lt;code&gt;GooglePayment&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  Si es &lt;code&gt;PAYPAL&lt;/code&gt; → devuelve un &lt;code&gt;PaypalPayment&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt; El sistema llama a &lt;code&gt;doPayment()&lt;/code&gt; sin importar el tipo de pago, porque todas las clases implementan la misma interfaz &lt;code&gt;Payment&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  ¿Cómo se usa la fábrica?
&lt;/h3&gt;

&lt;p&gt;El código que necesita un objeto de pago (el "cliente") ya no tiene que saber cómo crear un &lt;code&gt;CardPayment&lt;/code&gt; o un &lt;code&gt;GooglePayment&lt;/code&gt;. Simplemente le pide a la fábrica el tipo que necesita y trabaja con la interfaz &lt;code&gt;Payment&lt;/code&gt;.&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;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// El cliente solo pide el tipo de pago que quiere&lt;/span&gt;
        &lt;span class="nc"&gt;Payment&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PaymentFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;buildPayment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TypePayment&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;CARD&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;doPayment&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Salida: Making payment with Card&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;
  
  
  👉 En resumen:
&lt;/h3&gt;

&lt;p&gt;Este diagrama muestra un patrón Factory donde una fábrica centraliza la creación de diferentes tipos de pago, usando un &lt;code&gt;enum&lt;/code&gt; para decidir qué clase concreta instanciar.&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%2F5i9pna3t6pcmnu8mzej4.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%2F5i9pna3t6pcmnu8mzej4.png" alt=" " width="800" height="670"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adaptándolo "a lo Criollo": Una Picantería en Manabí
&lt;/h2&gt;

&lt;p&gt;Ahora, ¡vamos a lo nuestro! Olvidémonos de los pagos y la tecnología por un momento y pensemos en algo que nos identifica: la comida.&lt;/p&gt;

&lt;p&gt;Imagina que estamos montando el software para una picantería en Portoviejo. En Manabí, un mismo plato puede tener variaciones. Por ejemplo, un "ceviche" puede ser de pescado, de camarón, o mixto. Todos son ceviches, pero se preparan de forma ligeramente distinta.&lt;/p&gt;

&lt;p&gt;Aquí es donde el Factory Method brilla.&lt;/p&gt;




&lt;h3&gt;
  
  
  💻 Código Fuente del Ejemplo
&lt;/h3&gt;

&lt;p&gt;Puedes encontrar todo el código de este ejemplo en la carpeta del proyecto en GitHub:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://github.com/edzamo/software-engineering/tree/main/design-pattern/udemy-course/src/main/java/ec/com/pattern/creational/factorymethod/cevichemanabita" rel="noopener noreferrer"&gt; &lt;strong&gt;Ver el código del ejemplo del Ceviche Manabita&lt;/strong&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Estructura de archivos (ejemplo)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
 ├─ Ceviche.java                # interfaz producto
 ├─ CevicheType.java            # enum con tipos
 ├─ FishCeviche.java
 ├─ ShrimpCeviche.java
 ├─ MixedCeviche.java
 ├─ JipijapaCeviche.java
 └─ ManabitaRestaurantFactory.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fzdnotww7icwoit72376r.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%2Fzdnotww7icwoit72376r.png" alt=" " width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>designpatterns</category>
    </item>
    <item>
      <title>🧠 Microservice with Hexagonal Architecture using AI (Copilot + Gemini + Spring Boot)</title>
      <dc:creator>Edwin Zamora</dc:creator>
      <pubDate>Sat, 12 Jul 2025 19:41:39 +0000</pubDate>
      <link>https://dev.to/edzamo/microservice-with-hexagonal-architecture-using-ai-copilot-gemini-spring-boot-377l</link>
      <guid>https://dev.to/edzamo/microservice-with-hexagonal-architecture-using-ai-copilot-gemini-spring-boot-377l</guid>
      <description>&lt;h2&gt;
  
  
  🚀 Introduction
&lt;/h2&gt;

&lt;p&gt;This article explores how to build a back-end microservice using only free AI tools through custom instructions.&lt;br&gt;
The goal is to demonstrate how convenient and powerful it can be to use AI to generate professionally structured projects, without manually writing every line of code.&lt;/p&gt;




&lt;h2&gt;
  
  
  👁️ What do I want to prove?
&lt;/h2&gt;

&lt;p&gt;How far can we go building a professional microservice with AI as our co-pilot?&lt;br&gt;
In this case, we used &lt;strong&gt;Gemini&lt;/strong&gt; and &lt;strong&gt;Copilot&lt;/strong&gt; for the development and implementation of the software.&lt;/p&gt;

&lt;p&gt;This experiment shows that AI, when properly guided, can assist technical development without replacing the programmer. It works as a "technical assistant" that responds to our custom instructions, helping to apply best practices and maintain design quality.&lt;/p&gt;




&lt;h2&gt;
  
  
  📖 Core Reference: Hexagonal Architecture Explained
&lt;/h2&gt;

&lt;p&gt;For a foundational understanding of hexagonal architecture, this project is based on the excellent article by Arho Huttunen:&lt;br&gt;
🔗 &lt;a href="https://www.arhohuttunen.com/hexagonal-architecture-spring-boot/" rel="noopener noreferrer"&gt;Hexagonal Architecture with Spring Boot – arhohuttunen.com&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🧡 What's included in this POC?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🧹 Hexagonal architecture: decoupled inputs/outputs, clean domain.&lt;/li&gt;
&lt;li&gt;☕ Spring Boot 3 with professional dependencies.&lt;/li&gt;
&lt;li&gt;🐳 Containers with Docker Compose and MySql.&lt;/li&gt;
&lt;li&gt;🔁 DTO ↔ Entity mapping with MapStruct.&lt;/li&gt;
&lt;li&gt;🧪 Unit tests with JUnit and Mockito.&lt;/li&gt;
&lt;li&gt;📘 Documentation with Swagger/OpenAPI.&lt;/li&gt;
&lt;li&gt;🤖 Generated using AI: GitHub Copilot and Gemini.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔗 &lt;strong&gt;View the repository:&lt;/strong&gt; &lt;a href="https://github.com/edzamo/coffee-shop-hexagonal-con-IA" rel="noopener noreferrer"&gt;github.com/edzamo/coffee-shop-hexagonal-con-IA&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 How to generate structured code with AI
&lt;/h2&gt;

&lt;p&gt;Using AI to code isn't just about asking for code.&lt;br&gt;
It's about teaching it the &lt;strong&gt;context of your project&lt;/strong&gt;, guiding it with &lt;strong&gt;clear prompts&lt;/strong&gt;, and reviewing each response critically.&lt;/p&gt;

&lt;p&gt;During this development, I discovered that AI can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand complex patterns like hexagonal architecture.&lt;/li&gt;
&lt;li&gt;Generate coherent and well-named classes.&lt;/li&gt;
&lt;li&gt;Suggest effective unit tests.&lt;/li&gt;
&lt;li&gt;Validate project designs and structures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 Tip: if you define your own prompts and folder structures (like in &lt;code&gt;.heHexaBarista&lt;/code&gt;), you can turn AI into a &lt;strong&gt;real technical co-pilot&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✨ The deep benefit of using AI in software development
&lt;/h2&gt;

&lt;p&gt;Tools like Copilot and Gemini not only speed up work, but also help maintain code consistency and quality.&lt;/p&gt;

&lt;p&gt;They become constant technical assistants that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧠 Reduce repetitive effort.&lt;/li&gt;
&lt;li&gt;⚙️ Respect your style and conventions.&lt;/li&gt;
&lt;li&gt;🚀 Let you focus on business logic and architecture decisions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key is to &lt;strong&gt;use custom instructions and provide technical context&lt;/strong&gt;. This way, AI stops being generic and becomes a highly productive tool.&lt;/p&gt;

&lt;p&gt;🛑 &lt;strong&gt;AI doesn't replace the developer, it empowers them.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠️ How to practice with AI while coding
&lt;/h2&gt;

&lt;p&gt;Personal recommendations to take advantage of AI in real projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;💡 Start with simple projects and apply real patterns (like MVC or hexagonal architecture).&lt;/li&gt;
&lt;li&gt;🤭 Provide context: class names, folder structure, conventions.&lt;/li&gt;
&lt;li&gt;✍️ Use clear and step-by-step prompts, as if explaining to a junior.&lt;/li&gt;
&lt;li&gt;🧪 Review everything the AI generates. Learn from its mistakes and successes.&lt;/li&gt;
&lt;li&gt;📁 Define a clear structure (adapters, ports, domain) so AI can understand it easily.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧾 Conclusion
&lt;/h2&gt;

&lt;p&gt;This project not only demonstrates a functional architecture, but also &lt;strong&gt;how to integrate AI into a professional development workflow&lt;/strong&gt;.&lt;br&gt;
When properly guided, AI allows you to develop faster without sacrificing design or quality.&lt;/p&gt;

&lt;p&gt;If you want to try it yourself:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Explore the &lt;code&gt;.heHexaBarista&lt;/code&gt; folder.&lt;/li&gt;
&lt;li&gt;Install GitHub Copilot or Gemini.&lt;/li&gt;
&lt;li&gt;Build with AI as your technical ally. 🚀&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>java</category>
      <category>springboot</category>
      <category>microservices</category>
      <category>githubcopilot</category>
    </item>
    <item>
      <title>🧠 Microservicio con arquitectura hexagonal usando IA (Copilot + Gemini + Spring Boot)</title>
      <dc:creator>Edwin Zamora</dc:creator>
      <pubDate>Sat, 12 Jul 2025 19:03:29 +0000</pubDate>
      <link>https://dev.to/edzamo/microservicio-con-arquitectura-hexagonal-usando-ia-copilot-gemini-spring-boot-igb</link>
      <guid>https://dev.to/edzamo/microservicio-con-arquitectura-hexagonal-usando-ia-copilot-gemini-spring-boot-igb</guid>
      <description>&lt;h2&gt;
  
  
  🚀 Introducción
&lt;/h2&gt;

&lt;p&gt;Este artículo explora cómo construir un microservicio back-end utilizando únicamente herramientas de IA gratuitas, a través de instrucciones personalizadas.&lt;br&gt;&lt;br&gt;
El objetivo es demostrar lo cómodo y poderoso que puede ser el uso de IA para generar proyectos estructurados profesionalmente, sin necesidad de escribir cada línea de código manualmente.&lt;/p&gt;




&lt;h2&gt;
  
  
  📖 Referencia principal: Arquitectura Hexagonal explicada
&lt;/h2&gt;

&lt;p&gt;Para entender el enfoque base de este proyecto, revisa este excelente artículo:&lt;br&gt;&lt;br&gt;
🔗 &lt;a href="https://www.arhohuttunen.com/hexagonal-architecture-spring-boot/" rel="noopener noreferrer"&gt;arhohuttunen.com/hexagonal-architecture-spring-boot&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  👁️‍🗨️ ¿Qué quiero probar?
&lt;/h2&gt;

&lt;p&gt;¿Hasta dónde podemos llegar construyendo un microservicio profesional con IA como copiloto?&lt;br&gt;&lt;br&gt;
En este caso, usamos &lt;strong&gt;Gemini&lt;/strong&gt; y &lt;strong&gt;Copilot&lt;/strong&gt; para el desarrollo e implementación del software.&lt;/p&gt;

&lt;p&gt;Este experimento demuestra que la IA, bien guiada, puede acompañar el desarrollo técnico sin reemplazar al programador. Funciona como un “asistente técnico” que responde a nuestras instrucciones personalizadas, ayudando a aplicar buenas prácticas y mantener la calidad del diseño.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧱 ¿Qué contiene este POC?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🧩 Arquitectura hexagonal: entradas/salidas desacopladas, dominio limpio.&lt;/li&gt;
&lt;li&gt;☕ Spring Boot 3 con dependencias profesionales.&lt;/li&gt;
&lt;li&gt;🐳 Contenedores con Docker Compose y MySql.&lt;/li&gt;
&lt;li&gt;🔁 Mapeo DTO ↔ Entidades con MapStruct.&lt;/li&gt;
&lt;li&gt;🧪 Pruebas unitarias con JUnit y Mockito.&lt;/li&gt;
&lt;li&gt;📘 Documentación con Swagger/OpenAPI.&lt;/li&gt;
&lt;li&gt;🤖 Generado usando IA: GitHub Copilot y Gemini.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔗 &lt;strong&gt;Ver el repositorio:&lt;/strong&gt; &lt;a href="https://github.com/edzamo/coffee-shop-hexagonal-con-IA" rel="noopener noreferrer"&gt;github.com/edzamo/coffee-shop-hexagonal-con-IA&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Cómo generar código estructurado con IA
&lt;/h2&gt;

&lt;p&gt;Usar IA para codificar no se trata simplemente de pedirle código.&lt;br&gt;&lt;br&gt;
Es enseñarle el &lt;strong&gt;contexto de tu proyecto&lt;/strong&gt;, guiarla con &lt;strong&gt;prompts claros&lt;/strong&gt;, y revisar cada respuesta con sentido crítico.&lt;/p&gt;

&lt;p&gt;Durante este desarrollo, descubrí que la IA puede:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Entender patrones complejos como la arquitectura hexagonal.&lt;/li&gt;
&lt;li&gt;Generar clases coherentes y bien nombradas.&lt;/li&gt;
&lt;li&gt;Sugerir pruebas unitarias efectivas.&lt;/li&gt;
&lt;li&gt;Validar diseños y estructuras del proyecto.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 Tip: si defines tus propios prompts y estructuras de carpetas (como en &lt;code&gt;.heHexaBarista&lt;/code&gt;), puedes convertir a la IA en una &lt;strong&gt;copiloto técnica real&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✨ El profundo beneficio de usar la IA al desarrollar software
&lt;/h2&gt;

&lt;p&gt;Herramientas como Copilot y Gemini no solo aceleran el trabajo, sino que también ayudan a mantener la coherencia y calidad en el código.&lt;/p&gt;

&lt;p&gt;Se convierten en asistentes técnicos constantes que:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧠 Disminuyen el esfuerzo repetitivo.&lt;/li&gt;
&lt;li&gt;⚙️ Respetan tu estilo y convenciones.&lt;/li&gt;
&lt;li&gt;🚀 Te permiten concentrarte en la lógica de negocio y decisiones de arquitectura.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;La clave está en &lt;strong&gt;usar instrucciones personalizadas y brindar contexto técnico&lt;/strong&gt;. Así, la IA deja de ser genérica y se convierte en una herramienta altamente productiva.&lt;/p&gt;

&lt;p&gt;🛑 &lt;strong&gt;La IA no reemplaza al desarrollador, lo potencia.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠️ Cómo practicar con IA al codificar
&lt;/h2&gt;

&lt;p&gt;Recomendaciones personales para aprovechar IA en proyectos reales:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;💡 Empieza con proyectos simples y aplica patrones reales (como MVC o arquitectura hexagonal).&lt;/li&gt;
&lt;li&gt;🧭 Dale contexto: nombres de clases, estructura de carpetas, convenciones.&lt;/li&gt;
&lt;li&gt;✍️ Usa prompts claros y paso a paso, como si explicaras a un junior.&lt;/li&gt;
&lt;li&gt;🧪 Revisa todo lo que genere la IA. Aprende de sus errores y aciertos.&lt;/li&gt;
&lt;li&gt;📁 Define una estructura clara (adaptadores, puertos, dominio) para que la IA la entienda fácilmente.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧾 Conclusión
&lt;/h2&gt;

&lt;p&gt;Este proyecto no solo demuestra una arquitectura funcional, sino también &lt;strong&gt;cómo integrar IA en un flujo de trabajo profesional&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Cuando se le guía bien, la IA permite desarrollar más rápido sin sacrificar diseño ni calidad.&lt;/p&gt;

&lt;p&gt;Si quieres probarlo tú mismo:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Explora la carpeta &lt;code&gt;.heHexaBarista&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Instala GitHub Copilot o Gemini.&lt;/li&gt;
&lt;li&gt;Crea con IA como tu aliada técnica. 🚀&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>spanish</category>
      <category>microservices</category>
      <category>java</category>
      <category>spring</category>
    </item>
  </channel>
</rss>
