<?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: Kolawole Yusuf</title>
    <description>The latest articles on Forem by Kolawole Yusuf (@kola_yusuf).</description>
    <link>https://forem.com/kola_yusuf</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%2F2173844%2Fffc6c5fd-1c44-4f50-b550-e664ffdfc551.png</url>
      <title>Forem: Kolawole Yusuf</title>
      <link>https://forem.com/kola_yusuf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kola_yusuf"/>
    <language>en</language>
    <item>
      <title>Building a Security System, with motion detection and time based settings using Arduino</title>
      <dc:creator>Kolawole Yusuf</dc:creator>
      <pubDate>Fri, 13 Dec 2024 23:18:09 +0000</pubDate>
      <link>https://forem.com/kola_yusuf/building-a-security-system-with-motion-detection-and-time-based-settings-using-arduino-1m4</link>
      <guid>https://forem.com/kola_yusuf/building-a-security-system-with-motion-detection-and-time-based-settings-using-arduino-1m4</guid>
      <description>&lt;p&gt;Home security is a priority in the modern world and setting up a personalized do it yourself motion sensing security setup can enhance the safety of your residence and provide you with a sense of assurance. In this project, we will construct a Motion Sensitive Security System utilizing an Arduino Uno along with a 6-channel relay module that manages lighting and alerts triggered by motion detection. The special feature of this project involves adjusting the systems actions based on the time of day and whether its a weekday or weekend.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;You can use a 2-channel relay module for this project. Opting for a relay module with more than 2 channels allows us to expand the project later in the future. We will be able to control more devices without having to replace the existing modules.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Here is an explanation of how the system is going to function&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If there is any motion sensed, between 19:00 and 6:00; the lights and alarms will activate automatically.&lt;/li&gt;
&lt;li&gt;During weekdays, from 6:00 and 18:00; the alarm will be activated if there is any movement detected.&lt;/li&gt;
&lt;li&gt;During weekends the alarm will relaxed from 8:00 and 18:00; however the lights will continue working after 19:00.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;This initiative serves as a foundation, for tailoring home security setups and can be effortlessly enhanced to include smartphone alerts and advanced security features for both home and away modes.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Items Required:&lt;/li&gt;
&lt;li&gt;  Arduino Uno board&lt;/li&gt;
&lt;li&gt;  PIR motion sensor (for motion detection)&lt;/li&gt;
&lt;li&gt;  6-channel relay module&lt;/li&gt;
&lt;li&gt;  Buzzer or siren (for alarm)&lt;/li&gt;
&lt;li&gt;  LED lights or 12V lights (to simulate external lighting)&lt;/li&gt;
&lt;li&gt;  RTC module (Real Time Clock for keeping track of time)&lt;/li&gt;
&lt;li&gt;  Jumper wires&lt;/li&gt;
&lt;li&gt;  Breadboard&lt;/li&gt;
&lt;li&gt;  Power source (Arduino-compatible)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1. Setting up and wiring the circuits.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;PIR Motion Sensor&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Connect the VCC pin to the Arduino 5 volt pin.&lt;/li&gt;
&lt;li&gt;  Connect the sensors GND pin to the GND pin of the Arduino board.&lt;/li&gt;
&lt;li&gt;  Connect the signal pin to pin 2 on the Arduino (use any digital pin that is free, for use).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The 6 Channel Relay Module is a tool, for controlling multiple circuits or devices&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6-Channel Relay Module:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect the VCC wire to the 5 volt pin, on the Arduino board.&lt;/li&gt;
&lt;li&gt;Connect the ground (abbreviated as GND) of the sensor, to the ground (also labeled as GND) on the Arduino board.&lt;/li&gt;
&lt;li&gt;Connect IN 01 to the pin 3 on the Arduino board, for controlling the lights.&lt;/li&gt;
&lt;li&gt;Connect IN 1 and IN 3 to the pin 4 on Arduino, for alarm control.&lt;/li&gt;
&lt;li&gt;Alarm/Buzzer&lt;/li&gt;
&lt;li&gt;Connect to a relay channel in the 6-channel relay module&lt;/li&gt;
&lt;li&gt;Lights&lt;/li&gt;
&lt;li&gt;Connect to another replay channel on the 6-channel replay module&lt;/li&gt;
&lt;li&gt;RTC Module (DS3231)&lt;/li&gt;
&lt;li&gt;Connect the SDA pin to Arduino A4&lt;/li&gt;
&lt;li&gt;Connect SCL pin to Arduni A5&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sept 2. Writing the Arduino code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Lets now develop the program that combines detecting movement with controlling the relays based on time intervals.&lt;/li&gt;
&lt;li&gt;Open a new sketch in your Arduino IDE&lt;/li&gt;
&lt;li&gt;Select your board and run the code below&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;You have the option to replicate the build process and run the code on tinkercard.com without requiring an Arduino board or motion sensor and RTC module.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;Wire.h&amp;gt;
#include &amp;lt;RTClib.h&amp;gt;
RTC_DS3231 rtc; //Real Time Clock object

int motionSensor = 2; //the PIR sensor input pin
int relayLight = 3; //the relay controlling the light
int relayAlarm = 4; //the relay controlling the alarm
bool motionDetected = false; //initial motion state

void setup() {

pinMode(motionSensor, INPUT);
pinMode(relayLight, OUTPUT);
pinMode(relayAlarm, OUTPUT);

if (!rtc.begin()) {
Serial.println("Couldn not find RTC"); //RTC might not be connected to the Arduino board
while (1);
}

if (rtc.lostPower()) {
//Set the current date and time
rtc.adjust(DateTime(F(DATE), F(TIME)));
}

Serial.begin(9600);

}

void loop() {
DateTime now = rtc.now();
int dayOfWeek = now.dayOfTheWeek(); //Sunday = 0, Monday = 1 and Saturday = 6

int hour = now.hour(); //Get the current hour
motionDetected = digitalRead(motionSensor) == HIGH;

if (motionDetected) {
//If current time is between 19:00 and 6:00, turn on light and alarm
if (hour &amp;gt;= 19 || hour &amp;lt; 6) {

digitalWrite(relayLight, HIGH); //Turn on the light
digitalWrite(relayAlarm, HIGH); //Turn on the alarm

}

//If it's between 8:00 and 18:00 on weekdays, only trigger the alarm
else if (hour &amp;gt;= 8 &amp;amp;&amp;amp; hour &amp;lt; 18 &amp;amp;&amp;amp; (dayOfWeek &amp;gt;= 1 &amp;amp;&amp;amp; dayOfWeek &amp;lt;= 5)) {
digitalWrite(relayAlarm, HIGH); //Only turn on the alarm
}

}
else {
//Turn everything off when no motion is detected
digitalWrite(relayLight, LOW);
digitalWrite(relayAlarm, LOW);

}
delay(500); //Add a slight delay for debouncing

}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  How the code works
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;RTC integration:&lt;/strong&gt; The RTC module retrieves the day of the week and the current hour, enabling us to set up actions depending on the time of day and whether it is a weekday or weekend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motion detection:&lt;/strong&gt; When the PIR motion sensor senses/detects movement, Arduino then verifies the time, applies varying logic depending on the time of day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Relay control:&lt;/strong&gt; Is used for turning lights or the alarm system based on the time of day or day of the week.&lt;/p&gt;

&lt;h1&gt;
  
  
  Potential Future Developments
&lt;/h1&gt;

&lt;p&gt;There are ways to boost the effectiveness and user friendliness of this DIY security system.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Home/Away Mode: Set up the system on a display panel or mobile app, for the homeowner to set the system to home or away mode. In home mode (between 8:00 and 18:00) if there is motion detected, a notification will be sent to the user’s phone. If no response is received within a time period (like 3 minutes) the alarm will go off automatically. The away mode will operate as it currently does without any changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integrate a Wi-Fi module, like the ESP8266 to send notifications, to your smartphone when motion is detected while in home mode so you can respond before the alarm goes off.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Include more sensors, like door/window sensors to boost the security system’s effectiveness, providing an additional safeguard to protect all access points effectively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adding a surveillance camera for video recording or live streaming when motion is sensed could be useful for monitoring the property. The display panel or mobile app can automatically stream and switch to the camera where motion was detected.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By expanding the setup you can develop a reliable home security system tailored to your individual requirements.&lt;/p&gt;

</description>
      <category>arduino</category>
      <category>security</category>
      <category>automation</category>
      <category>diy</category>
    </item>
    <item>
      <title>SOLID Code, Solid Results</title>
      <dc:creator>Kolawole Yusuf</dc:creator>
      <pubDate>Sun, 01 Dec 2024 11:42:08 +0000</pubDate>
      <link>https://forem.com/kola_yusuf/solid-code-solid-results-l9</link>
      <guid>https://forem.com/kola_yusuf/solid-code-solid-results-l9</guid>
      <description>&lt;p&gt;Looking at a codebase had me questioning how I got tangled up in such complexity. Each line of code felt like a maze of dense forest without a map.&lt;/p&gt;

&lt;p&gt;When I first heard about SOLID principles, I'll be honest, I rolled my eyes. Another set of academic-sounding programming rules that seemed more like theoretical mumbo-jumbo than practical advice. I mean, who has time to think about complex design principles when you're just trying to get code working, right?&lt;/p&gt;

&lt;p&gt;But something changed as I dove deeper into more complex software projects. Those seemingly abstract guidelines started to make real sense. I began to see how these principles weren't just academic theories, but powerful tools that could actually make my life as a developer easier. Projects that used to feel like tangled messes started to become more manageable, more logical.&lt;/p&gt;

&lt;p&gt;Now, as an experienced developer, I code with SOLID principles in mind, which has consistently helped me write maintainable, scalable, and robust code. SOLID represents five principles which are like a compass that helps developers to navigate through the complex system and to develop such software which are not only reliable but also beautiful, flexible and long lived. Robert C Martin, also known as Uncle Bob developed the principles, which are widely regarded as the cornerstone of effective software design.&lt;/p&gt;

&lt;p&gt;Let me break down each principle with real world examples from my own development experience:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;S - Single Responsibility Principle (SRP)&lt;/strong&gt;&lt;br&gt;
Think of SRP like organizing your toolbox. Each tool has a specific purpose, and so should your classes.&lt;br&gt;
Here's a before and after sample code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Before: A messy, do-everything class
class UserManager {
  createUser(userData) {
    // Validate user data
    if (!userData.email || !userData.password) {
      throw new Error('Invalid user data');
    }

    // Save user to database
    const db = new Database();
    db.save('users', userData);

    // Send welcome email
    const emailService = new EmailService();
    emailService.sendWelcomeEmail(userData.email);
  }
}

// After: Separated responsibilities
class UserValidator {
  validate(userData) {
    if (!userData.email || !userData.password) {
      throw new Error('Invalid user data');
    }
  }
}

class UserRepository {
  save(userData) {
    const db = new Database();
    db.save('users', userData);
  }
}

class UserNotificationService {
  sendWelcome(email) {
    const emailService = new EmailService();
    emailService.sendWelcomeEmail(email);
  }
}

class UserManager {
  constructor(validator, repository, notificationService) {
    this.validator = validator;
    this.repository = repository;
    this.notificationService = notificationService;
  }

  createUser(userData) {
    this.validator.validate(userData);
    this.repository.save(userData);
    this.notificationService.sendWelcome(userData.email);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;O - Open/Closed Principle (OCP)&lt;/strong&gt;&lt;br&gt;
I learned this principle the hard way. Imagine building a payment processing system that needs to support multiple payment methods without rewriting existing code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Payment processor that's open for extension
class PaymentProcessor {
  processPayment(paymentMethod, amount) {
    switch(paymentMethod) {
      case 'stripe':
        return this.processStripe(amount);
      case 'paypal':
         return this.processPayStack(amount);
      default:
        throw new Error('Unsupported payment method');
    }
  }

  processStripe(amount) {
    // Stripe processing logic
  }

  processPayPal(amount) {
    // PayPal processing logic
  }


}

// Better approach using strategy pattern
class PaymentStrategy {
  process(amount) {
    throw new Error('Must implement process method');
  }
}

class StripePayment extends PaymentStrategy {
  process(amount) {
    // Specific Stripe processing
  }
}

class PayPalPayment extends PaymentStrategy {
  process(amount) {
    // Specific PayPal processing
  }
}

class PaymentProcessor {
  constructor(strategy) {
    this.strategy = strategy;
  }

  processPayment(amount) {
    return this.strategy.process(amount);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;L - Liskov Substitution Principle (LSP)&lt;/strong&gt;&lt;br&gt;
This principle taught me to ensure that derived classes can replace base classes without breaking the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Problematic implementation
class SportsCar {
  accelerate() {
    console.log('Rapid acceleration, 0-60 in 3.2 seconds');
  }

  turboBoost() {
    console.log('Engaging turbo boost for maximum speed');
  }
}

class ElectricCar extends SportsCar {
  turboBoost() {
    // Electric cars don't have traditional turbo boost
    throw new Error('Turbo boost not supported in electric vehicles');
  }
}

class LuxuryCar extends SportsCar {
  turboBoost() {
    // Luxury car prioritizes comfort over speed
    console.log('Gentle acceleration mode engaged');
  }
}

// Better approach following LSP
class Car {
  accelerate() {
    throw new Error('Must implement accelerate method');
  }
}

class PerformanceCar extends Car {
  accelerate() {
    console.log('High-performance acceleration');
  }

  turboBoost() {
    console.log('Maximum speed boost activated');
  }
}

class ElectricPerformanceCar extends Car {
  accelerate() {
    console.log('Instant electric acceleration');
  }

  // No turbo boost, but maintains the car's core functionality
}

class LuxuryCar extends Car {
  accelerate() {
    console.log('Smooth, controlled acceleration');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;I - Interface Segregation Principle (ISP)&lt;/strong&gt;&lt;br&gt;
I used to create massive interfaces that forced classes to implement methods they didn't need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Before: Bloated interface
class AllInOnePrinter {
  print() { /* print logic */ }
  scan() { /* scan logic */ }
  fax() { /* fax logic */ }
}

// After: Segregated interfaces
class Printer {
  print() { /* print logic */ }
}

class Scanner {
  scan() { /* scan logic */ }
}

class FaxMachine {
  fax() { /* fax logic */ }
}

class MultiFunctionDevice {
  constructor(printer, scanner, faxMachine) {
    this.printer = printer;
    this.scanner = scanner;
    this.faxMachine = faxMachine;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;D - Dependency Inversion Principle (DIP)&lt;br&gt;
This principle changed how I think about module dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Dependency Injection
class NotificationService {
  constructor(communicationStrategy) {
    this.communicationStrategy = communicationStrategy;
  }

  notify(message) {
    this.communicationStrategy.send(message);
  }
}

class EmailStrategy {
  send(message) {
    // Email sending logic
  }
}

class SMSStrategy {
  send(message) {
    // SMS sending logic
  }
}

// Usage
const emailNotification = new NotificationService(new EmailStrategy());
const smsNotification = new NotificationService(new SMSStrategy());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why I can't do without SOLID&lt;/strong&gt;&lt;br&gt;
Implementing these principles has transformed how I build software:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;My code is more readable&lt;/li&gt;
&lt;li&gt;Changes are less painful&lt;/li&gt;
&lt;li&gt;Testing becomes significantly easier&lt;/li&gt;
&lt;li&gt;I can add features without a complete rewrite&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;My Advice for Getting Started&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Review your code regularly&lt;/li&gt;
&lt;li&gt;Practice these principles in small, manageable chunks&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
SOLID principles are the closest thing to magic in software development. They have transformed complex, brittle code into flexible and maintainable systems for me. Great software is thoughtfully crafted and continually improved&lt;/p&gt;

</description>
    </item>
    <item>
      <title>SOLID Code, Solid Results</title>
      <dc:creator>Kolawole Yusuf</dc:creator>
      <pubDate>Sun, 01 Dec 2024 11:42:08 +0000</pubDate>
      <link>https://forem.com/kola_yusuf/solid-code-solid-results-keo</link>
      <guid>https://forem.com/kola_yusuf/solid-code-solid-results-keo</guid>
      <description>&lt;p&gt;Looking at a codebase had me questioning how I got tangled up in such complexity. Each line of code felt like a maze of dense forest without a map.&lt;/p&gt;

&lt;p&gt;When I first heard about SOLID principles, I'll be honest, I rolled my eyes. Another set of academic-sounding programming rules that seemed more like theoretical mumbo-jumbo than practical advice. I mean, who has time to think about complex design principles when you're just trying to get code working, right?&lt;/p&gt;

&lt;p&gt;But something changed as I dove deeper into more complex software projects. Those seemingly abstract guidelines started to make real sense. I began to see how these principles weren't just academic theories, but powerful tools that could actually make my life as a developer easier. Projects that used to feel like tangled messes started to become more manageable, more logical.&lt;/p&gt;

&lt;p&gt;Now, as an experienced developer, I code with SOLID principles in mind, which has consistently helped me write maintainable, scalable, and robust code. SOLID represents five principles which are like a compass that helps developers to navigate through the complex system and to develop such software which are not only reliable but also beautiful, flexible and long lived. Robert C Martin, also known as Uncle Bob developed the principles, which are widely regarded as the cornerstone of effective software design.&lt;/p&gt;

&lt;p&gt;Let me break down each principle with real world examples from my own development experience:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;S - Single Responsibility Principle (SRP)&lt;/strong&gt;&lt;br&gt;
Think of SRP like organizing your toolbox. Each tool has a specific purpose, and so should your classes.&lt;br&gt;
Here's a before and after sample code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Before: A messy, do-everything class
class UserManager {
  createUser(userData) {
    // Validate user data
    if (!userData.email || !userData.password) {
      throw new Error('Invalid user data');
    }

    // Save user to database
    const db = new Database();
    db.save('users', userData);

    // Send welcome email
    const emailService = new EmailService();
    emailService.sendWelcomeEmail(userData.email);
  }
}

// After: Separated responsibilities
class UserValidator {
  validate(userData) {
    if (!userData.email || !userData.password) {
      throw new Error('Invalid user data');
    }
  }
}

class UserRepository {
  save(userData) {
    const db = new Database();
    db.save('users', userData);
  }
}

class UserNotificationService {
  sendWelcome(email) {
    const emailService = new EmailService();
    emailService.sendWelcomeEmail(email);
  }
}

class UserManager {
  constructor(validator, repository, notificationService) {
    this.validator = validator;
    this.repository = repository;
    this.notificationService = notificationService;
  }

  createUser(userData) {
    this.validator.validate(userData);
    this.repository.save(userData);
    this.notificationService.sendWelcome(userData.email);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;O - Open/Closed Principle (OCP)&lt;/strong&gt;&lt;br&gt;
I learned this principle the hard way. Imagine building a payment processing system that needs to support multiple payment methods without rewriting existing code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Payment processor that's open for extension
class PaymentProcessor {
  processPayment(paymentMethod, amount) {
    switch(paymentMethod) {
      case 'stripe':
        return this.processStripe(amount);
      case 'paypal':
         return this.processPayStack(amount);
      default:
        throw new Error('Unsupported payment method');
    }
  }

  processStripe(amount) {
    // Stripe processing logic
  }

  processPayPal(amount) {
    // PayPal processing logic
  }


}

// Better approach using strategy pattern
class PaymentStrategy {
  process(amount) {
    throw new Error('Must implement process method');
  }
}

class StripePayment extends PaymentStrategy {
  process(amount) {
    // Specific Stripe processing
  }
}

class PayPalPayment extends PaymentStrategy {
  process(amount) {
    // Specific PayPal processing
  }
}

class PaymentProcessor {
  constructor(strategy) {
    this.strategy = strategy;
  }

  processPayment(amount) {
    return this.strategy.process(amount);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;L - Liskov Substitution Principle (LSP)&lt;/strong&gt;&lt;br&gt;
This principle taught me to ensure that derived classes can replace base classes without breaking the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Problematic implementation
class SportsCar {
  accelerate() {
    console.log('Rapid acceleration, 0-60 in 3.2 seconds');
  }

  turboBoost() {
    console.log('Engaging turbo boost for maximum speed');
  }
}

class ElectricCar extends SportsCar {
  turboBoost() {
    // Electric cars don't have traditional turbo boost
    throw new Error('Turbo boost not supported in electric vehicles');
  }
}

class LuxuryCar extends SportsCar {
  turboBoost() {
    // Luxury car prioritizes comfort over speed
    console.log('Gentle acceleration mode engaged');
  }
}

// Better approach following LSP
class Car {
  accelerate() {
    throw new Error('Must implement accelerate method');
  }
}

class PerformanceCar extends Car {
  accelerate() {
    console.log('High-performance acceleration');
  }

  turboBoost() {
    console.log('Maximum speed boost activated');
  }
}

class ElectricPerformanceCar extends Car {
  accelerate() {
    console.log('Instant electric acceleration');
  }

  // No turbo boost, but maintains the car's core functionality
}

class LuxuryCar extends Car {
  accelerate() {
    console.log('Smooth, controlled acceleration');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;I - Interface Segregation Principle (ISP)&lt;/strong&gt;&lt;br&gt;
I used to create massive interfaces that forced classes to implement methods they didn't need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Before: Bloated interface
class AllInOnePrinter {
  print() { /* print logic */ }
  scan() { /* scan logic */ }
  fax() { /* fax logic */ }
}

// After: Segregated interfaces
class Printer {
  print() { /* print logic */ }
}

class Scanner {
  scan() { /* scan logic */ }
}

class FaxMachine {
  fax() { /* fax logic */ }
}

class MultiFunctionDevice {
  constructor(printer, scanner, faxMachine) {
    this.printer = printer;
    this.scanner = scanner;
    this.faxMachine = faxMachine;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;D - Dependency Inversion Principle (DIP)&lt;br&gt;
This principle changed how I think about module dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Dependency Injection
class NotificationService {
  constructor(communicationStrategy) {
    this.communicationStrategy = communicationStrategy;
  }

  notify(message) {
    this.communicationStrategy.send(message);
  }
}

class EmailStrategy {
  send(message) {
    // Email sending logic
  }
}

class SMSStrategy {
  send(message) {
    // SMS sending logic
  }
}

// Usage
const emailNotification = new NotificationService(new EmailStrategy());
const smsNotification = new NotificationService(new SMSStrategy());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why I can't do without SOLID&lt;/strong&gt;&lt;br&gt;
Implementing these principles has transformed how I build software:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;My code is more readable&lt;/li&gt;
&lt;li&gt;Changes are less painful&lt;/li&gt;
&lt;li&gt;Testing becomes significantly easier&lt;/li&gt;
&lt;li&gt;I can add features without a complete rewrite&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;My Advice for Getting Started&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Review your code regularly&lt;/li&gt;
&lt;li&gt;Practice these principles in small, manageable chunks&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
SOLID principles are the closest thing to magic in software development. They have transformed complex, brittle code into flexible and maintainable systems for me. Great software is thoughtfully crafted and continually improved&lt;/p&gt;

</description>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Kolawole Yusuf</dc:creator>
      <pubDate>Sat, 30 Nov 2024 08:05:13 +0000</pubDate>
      <link>https://forem.com/kola_yusuf/-5ccf</link>
      <guid>https://forem.com/kola_yusuf/-5ccf</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/kola_yusuf" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F2173844%2Fffc6c5fd-1c44-4f50-b550-e664ffdfc551.png" alt="kola_yusuf"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kola_yusuf/i-built-a-football-match-analysis-tool-and-open-sourced-it-l03" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;I built a football match analysis tool and open-sourced it! ⚽🚀&lt;/h2&gt;
      &lt;h3&gt;Kolawole Yusuf ・ Nov 29&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#vue&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#node&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#express&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>I built a football match analysis tool and open-sourced it! ⚽🚀</title>
      <dc:creator>Kolawole Yusuf</dc:creator>
      <pubDate>Fri, 29 Nov 2024 19:51:39 +0000</pubDate>
      <link>https://forem.com/kola_yusuf/i-built-a-football-match-analysis-tool-and-open-sourced-it-l03</link>
      <guid>https://forem.com/kola_yusuf/i-built-a-football-match-analysis-tool-and-open-sourced-it-l03</guid>
      <description>&lt;p&gt;Hi community! 😊&lt;br&gt;
I am excited to share Sport Insight, a tool I built to provide detailed football match analysis. Whether you are a football fan or a professional, Sport Insight is here to help you dive deeper into team performances and match statistics.&lt;/p&gt;

&lt;p&gt;Highlights:&lt;br&gt;
Analyze upcoming matches with detailed odds information.&lt;br&gt;
Review head-to-head stats and team performance for home and away games.&lt;/p&gt;

&lt;p&gt;Explore a sleek, Vue-powered frontend connected to a Node.js backend.&lt;br&gt;
What I’ve Achieved So Far:&lt;br&gt;
🚀 Improved match analysis with intuitive data visualization and actionable insights.&lt;br&gt;
🌟 Clean separation of backend and frontend for scalability and collaboration.&lt;br&gt;
Here’s the link to the repo: &lt;br&gt;
&lt;a href="https://github.com/CodeWithKola/sport-insight" rel="noopener noreferrer"&gt;https://github.com/CodeWithKola/sport-insight&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How You Can Support:&lt;br&gt;
Can you help me with a ⭐? Your feedback and contributions are welcome too!&lt;/p&gt;

&lt;p&gt;Let’s connect and make Sport Insight even better. 🎉&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>vue</category>
      <category>node</category>
      <category>express</category>
    </item>
    <item>
      <title>Combine Node.js and WordPress Under One Domain</title>
      <dc:creator>Kolawole Yusuf</dc:creator>
      <pubDate>Thu, 28 Nov 2024 01:37:40 +0000</pubDate>
      <link>https://forem.com/kola_yusuf/combine-nodejs-and-wordpress-under-one-domain-k11</link>
      <guid>https://forem.com/kola_yusuf/combine-nodejs-and-wordpress-under-one-domain-k11</guid>
      <description>&lt;p&gt;I have been tinkering with a website that merges a custom Node.js application with a WordPress blog, and I'm excited to share my journey.&lt;/p&gt;

&lt;p&gt;After experimenting with various hosting configurations, I discovered a straightforward approach to creating a seamless online presence using Nginx on AlmaLinux.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Important Note: Throughout this guide, replace example.com with your actual domain name. For instance, if your domain is mydomain.com, you'll substitute all instances of example.com with mydomain.com.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My goal was simple, build a setup where my main website runs on Node.js while maintaining a WordPress blog, all without sacrificing performance. For example, my primary domain example.com is powered by Node.js, while my blog lives at example.com/blog. Whether you are a developer looking to craft a unique web presence or someone eager to blend different technologies, this method has been a game-changer for me, offering consistent URL structure that helps search engines understand site hierarchy and provides significant SEO advantages.&lt;/p&gt;

&lt;p&gt;The real beauty of this setup is its adaptability. While I am using AlmaLinux, the core principles can be applied to virtually any Linux distribution you are comfortable with. It's all about finding that perfect balance between your custom application and content management needs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before getting started, ensure you have the following:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;AlmaLinux 8 or 9&lt;/li&gt;
&lt;li&gt;A server running Nginx&lt;/li&gt;
&lt;li&gt;Basic Node.js application setup &lt;/li&gt;
&lt;li&gt;WordPress setup &lt;/li&gt;
&lt;li&gt;Familiarity with Nginx configurations&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Prepare your server&lt;/strong&gt;&lt;br&gt;
You can install Nginx on AlmaLinux by first updating your system and installing the necessary dependencies using the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo dnf update -y
sudo dnf install -y epel-release
sudo dnf install -y nodejs npm nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: You can create a simple app using Express&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir my-node-app
cd my-node-app
npm init -y
npm install express //Install Express (or your preferred Node.js framework)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create basic Node.js application&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) =&amp;gt; {
  res.send('Welcome to my website!');
});

app.listen(port, () =&amp;gt; {
  console.log(`Node.js app running on port ${port}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use PM2 for process management&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo npm install -g pm2
pm2 start app.js
pm2 startup systemd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: WordPress installation&lt;/strong&gt;&lt;br&gt;
Download and extract WordPress&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /var/www/example.com
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress blog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Nginx configuration&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Create /etc/nginx/conf.d/example.com.conf&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;

    # Node.js application (root domain)
    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    # WordPress blog
    location /blog {
        alias /var/www/example.com/blog;
        try_files $uri $uri/ /blog/index.php?$args;

        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php-fpm/www.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Security and permissions&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chown -R nginx:nginx /var/www/example.com
sudo chmod -R 755 /var/www/example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6: Start services&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl enable nginx
sudo systemctl enable pm2-root
sudo systemctl start nginx
pm2 startup
pm2 save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
You now have a Node.js website operating as the primary site and a WordPress blog located at /blog within the same domain using Nginx. This setup provides a solution where each application can function separately while utilizing the same domain name, for streamlined content and web application management and deployment. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional recommendations&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implement SSL with Let's Encrypt&lt;/li&gt;
&lt;li&gt;Set up regular backups&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>wordpress</category>
      <category>nginx</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
