<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by hamza lamjounah on Medium]]></title>
        <description><![CDATA[Stories by hamza lamjounah on Medium]]></description>
        <link>https://medium.com/@hamzalamjounah0?source=rss-c1ea27d71f43------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Kr_N8jDabNyAXgjE9IORnw.png</url>
            <title>Stories by hamza lamjounah on Medium</title>
            <link>https://medium.com/@hamzalamjounah0?source=rss-c1ea27d71f43------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:53:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hamzalamjounah0/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SOLID Principles: Le Guide Ultime pour un Code de Qualité]]></title>
            <link>https://medium.com/@hamzalamjounah0/solid-principles-le-guide-ultime-pour-un-code-de-qualit%C3%A9-a269ae5e223c?source=rss-c1ea27d71f43------2</link>
            <guid isPermaLink="false">https://medium.com/p/a269ae5e223c</guid>
            <dc:creator><![CDATA[hamza lamjounah]]></dc:creator>
            <pubDate>Wed, 14 May 2025 20:57:20 GMT</pubDate>
            <atom:updated>2025-05-14T20:57:20.856Z</atom:updated>
            <content:encoded><![CDATA[<p><em>(Avec exemples en Java pour mieux comprendre)</em></p><h3>Introduction</h3><p>En tant que développeurs, nous voulons tous écrire du code :<br>✅ <strong>Facile à maintenir</strong><br>✅ <strong>Évolutif</strong><br>✅ <strong>Peu couplé</strong><br>✅ <strong>Testable</strong></p><p>Les <strong>principes SOLID</strong> (introduits par Robert C. Martin) sont la clé pour y parvenir. Décortiquons-les ensemble !</p><h3>1. SRP — Single Responsibility Principle</h3><p><strong>“Une classe = une seule responsabilité”</strong></p><p>❌ <strong>Problème</strong></p><pre>public class UserManager {<br>    public void createUser(User user) <br>    public void sendEmail(User user) <br>    public void saveToDatabase(User user) <br>}</pre><p>👉 <em>Si l’envoi d’emails change, on modifie </em><em>UserManager alors que ça ne concerne pas sa responsabilité principale.</em></p><h3>✅ Solution</h3><pre>public class UserCreator { public void create(User user) { /*...*/ } }<br>public class EmailSender { public void send(User user) { /*...*/ } }<br>public class UserRepository { public void save(User user) { /*...*/ } }</pre><p><strong>Bénéfices</strong> :</p><ul><li>Modifier l’envoi d’email n’affecte pas la gestion des utilisateurs.</li><li>Plus facile à tester.</li></ul><h3>2. OCP — Open/Closed Principle</h3><p><strong>“Ouvert à l’extension, fermé à la modification”</strong></p><h3>❌ Problème</h3><pre>public class PaymentProcessor {<br>    public void process(String paymentType) {<br>        if (paymentType.equals(&quot;PayPal&quot;)) { /*...*/ }<br>        else if (paymentType.equals(&quot;Stripe&quot;)) { /*...*/ }<br>    }<br>}</pre><h3>✅ Solution</h3><pre>public interface PaymentMethod { void process(); }<br><br>public class PayPal implements PaymentMethod { /*...*/ }<br>public class Stripe implements PaymentMethod { /*...*/ }<br>public class Crypto implements PaymentMethod { /*...*/ } <br><br>public class PaymentProcessor {<br>    public void process(PaymentMethod payment) {<br>        payment.process();<br>    }<br>}</pre><p><strong>Bénéfices</strong> :</p><ul><li>On ajoute des fonctionnalités <strong>sans toucher au code existant</strong>.</li></ul><h3>3. LSP — Liskov Substitution Principle</h3><p><strong>“Une sous-classe doit pouvoir remplacer sa classe parente”</strong></p><h3>❌ Problème</h3><pre>public class Rectangle {<br>    public void setWidth(int w) { /*...*/ }<br>    public void setHeight(int h) { /*...*/ }<br>}<br><br>public class Square extends Rectangle {<br>    @Override<br>    public void setWidth(int w) { <br>        super.setWidth(w);<br>        super.setHeight(w); <br>    }<br>}</pre><h3>✅ Solution</h3><pre>public interface Shape { int getArea(); }<br><br>public class Rectangle implements Shape { /*...*/ }<br>public class Square implements Shape { /*...*/ }</pre><p><strong>Bénéfices</strong> :</p><ul><li>Plus de risque de <strong>casser le comportement attendu</strong>.</li></ul><h3>4. ISP — Interface Segregation Principle</h3><p><strong>“Préférer des interfaces petites et spécifiques”</strong></p><h3>❌ Problème</h3><pre>public interface Machine {<br>    void print();<br>    void scan();<br>    void fax();<br>}<br><br>public class SimplePrinter implements Machine {<br>    public void print() {}<br>    public void scan() { throw new UnsupportedOperationException(); }<br>    public void fax() { throw new UnsupportedOperationException(); }<br>}</pre><h3>✅ Solution</h3><pre>public interface Printable { void print(); }<br>public interface Scannable { void scan(); }<br><br>public class SimplePrinter implements Printable {<br>    public void print() { System.out.println(&quot;Impression...&quot;); }<br>}</pre><p><strong>Bénéfices</strong> :</p><ul><li>Pas de <strong>méthodes inutiles imposées</strong>.</li></ul><h3>5. DIP — Dependency Inversion Principle</h3><p><strong>“Dépendre des abstractions, pas des implémentations”</strong></p><h3>❌ Problème</h3><pre>public class UserService {<br>    private MySQLDatabase db = new MySQLDatabase(); // Couplage fort !<br>}</pre><h3>✅ Solution</h3><pre>public interface Database { void save(User user); }<br><br>public class MySQLDatabase implements Database { /*...*/ }<br>public class MongoDB implements Database { /*...*/ }<br><br>public class UserService {<br>    private Database db; // Injecté via constructeur<br>    public UserService(Database db) { this.db = db; }<br>}</pre><p><strong>Bénéfices</strong> :</p><ul><li>On peut <strong>changer de base de données</strong> sans modifier UserService.</li><li><strong>Testable</strong> (on peut injecter un mock).</li></ul><h3>Conclusion : Pourquoi SOLID ?</h3><p><strong>Réduit la complexité</strong> → Moins de bugs.</p><p><strong>Facilite les tests</strong> → Code plus fiable.</p><p><strong>Permet l’évolutivité</strong> → Nouveaux besoins = nouvelles classes, sans tout réécrire.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a269ae5e223c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Log4j in Java: Elegant and Efficient Logging for Your Applications]]></title>
            <link>https://medium.com/@hamzalamjounah0/getting-started-with-log4j-in-java-elegant-and-efficient-logging-for-your-applications-3ace9935ad5f?source=rss-c1ea27d71f43------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ace9935ad5f</guid>
            <dc:creator><![CDATA[hamza lamjounah]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 16:48:23 GMT</pubDate>
            <atom:updated>2025-04-17T16:48:23.497Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of Java development, logging is not just a best practice — it’s a necessity. Whether you’re debugging issues, monitoring performance, or auditing system behavior, having a reliable logging mechanism in place is essential. This is where <strong>Log4j</strong> comes into play.</p><h4>What is Log4j?</h4><p><strong>Log4j</strong> is a powerful and flexible logging library for Java, part of the Apache Logging Services project. It allows developers to log runtime information at different levels of severity and output it to various destinations (console, files, databases, etc.).</p><h4>Why Use Log4j?</h4><ul><li>Separate logic from logging</li><li>Capture detailed runtime information</li><li>Send logs to multiple outputs (console, file, server)</li><li>Control verbosity levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL</li><li>Enable production-level monitoring with minimal overhead</li></ul><h4>Setting Up Log4j2 in a Java Project</h4><p>1️ Add Log4j2 dependency via Maven</p><pre>&lt;dependency&gt;<br>  &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;<br>  &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;<br>  &lt;version&gt;2.20.0&lt;/version&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>  &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;<br>  &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;<br>  &lt;version&gt;2.20.0&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>2️ Create a log4j2.xml configuration file</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;Configuration status=&quot;WARN&quot;&gt;<br>  &lt;Appenders&gt;<br>    &lt;Console name=&quot;Console&quot; target=&quot;SYSTEM_OUT&quot;&gt;<br>      &lt;PatternLayout pattern=&quot;%d{HH:mm:ss} %-5level %logger{36} - %msg%n&quot;/&gt;<br>    &lt;/Console&gt;<br>    &lt;File name=&quot;FileLogger&quot; fileName=&quot;logs/app.log&quot;&gt;<br>      &lt;PatternLayout pattern=&quot;%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n&quot;/&gt;<br>    &lt;/File&gt;<br>  &lt;/Appenders&gt;<br>  &lt;Loggers&gt;<br>    &lt;Root level=&quot;info&quot;&gt;<br>      &lt;AppenderRef ref=&quot;Console&quot;/&gt;<br>      &lt;AppenderRef ref=&quot;FileLogger&quot;/&gt;<br>    &lt;/Root&gt;<br>  &lt;/Loggers&gt;<br>&lt;/Configuration&gt;</pre><h4>Example: Logging in Action</h4><pre>import org.apache.logging.log4j.LogManager;<br>import org.apache.logging.log4j.Logger;<br><br>public class App {<br>    private static final Logger logger = LogManager.getLogger(App.class);<br><br>    public static void main(String[] args) {<br>        logger.info(&quot;Application started&quot;);<br>        try {<br>            int result = 10 / 2;<br>            logger.debug(&quot;Calculation result: &quot; + result);<br>        } catch (Exception e) {<br>            logger.error(&quot;An error occurred&quot;, e);<br>        }<br>        logger.info(&quot;Application finished&quot;);<br>    }<br>}</pre><h4>Important: Log4Shell Vulnerability</h4><p>In December 2021, a critical vulnerability (CVE-2021–44228, “Log4Shell”) affected older versions of Log4j. Always use the latest Log4j2 version and avoid Log4j 1.x.</p><h4>Final Thoughts</h4><p>Logging is one of the pillars of modern application development. With Log4j2, you get fine-grained control, high performance, and great flexibility in how you manage and visualize your logs.</p><p>Whether you’re building microservices, APIs, or desktop applications, integrating Log4j properly can save hours of debugging and provide critical insights into your system’s behavior.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ace9935ad5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>