ACID SOLID


ACID properties ensure data integrity and reliability in Relational Database Management Systems (RDBMS). 
ACID stands for:
1) ATOMICITY – Ensures that a transaction is all or nothing. If any part fails, the entire transaction is rolled back.
2) CONSISTENCY – Guarantees that a transaction maintains database integrity, ensuring valid state transitions.
3) ISOLATION – Prevents transactions from interfering with each other, ensuring concurrent execution does not cause conflicts.
4) DURABILITY – Ensures that once a transaction is committed, it remains permanent, even in case of system failures.

These properties help databases maintain accuracy, reliability, and consistency in multi-user environments.

-----------------------------------------------------------------------------------------------------------------------------

SOLID principles of Object-Oriented Programming (OOP)

A foundational set of design guidelines that help developers write cleaner, more maintainable code.

S – Single Responsibility Principle (SRP)
A class should have only one reason to change, meaning it should do just one thing.
For example, a `ReportPrinter` class shouldn’t also handle saving files to disk.

O – Open/Closed Principle (OCP)
Software entities should be open for extension but closed for modification.
You should be able to add new functionality without changing existing code—think plugins or subclassing.

L – Liskov Substitution Principle (LSP)
Objects of a superclass should be replaceable with objects of a subclass without breaking the application.
If `Bird` has a `fly()` method, then `Penguin` probably shouldn’t inherit from `Bird` unless it can fly too.

I – Interface Segregation Principle (ISP)
Clients shouldn’t be forced to depend on interfaces they don’t use.
It’s better to have many small, specific interfaces than one large, general-purpose one.

D – Dependency Inversion Principle (DIP)
High-level modules shouldn’t depend on low-level modules. Both should depend on abstractions.
This helps decouple code and makes it easier to test and maintain.

These principles were popularized by Robert C. Martin (aka Uncle Bob) and are a cornerstone of clean software architecture.

The SOLID principles in Java code examples:

Single Responsibility Principle (SRP)
Each class should have only one reason to change.
class Invoice {
  private List<Item> items;
    public double calculateTotal() {
      return items.stream().mapToDouble(Item::getPrice).sum();
    }
}
class InvoicePrinter {
  public void print(Invoice invoice) {
    System.out.println("Total: " + invoice.calculateTotal());
  }
}

Open/Closed Principle (OCP)
Open for extension, closed for modification.
interface Discount {
  double apply(double total);
}
class NoDiscount implements Discount {
  public double apply(double total) {
    return total;
  }
}
class PercentageDiscount implements Discount {
  public double apply(double total) {
    return total * 0.9; // 10% off
  }
}
class Invoice {
  private double total;
  private Discount discount;
  public Invoice(double total, Discount discount) {
    this.total = discount.apply(total);
  }
  public double getTotal() {
    return total;
  }
}

Liskov Substitution Principle (LSP)
Subtypes must be substitutable for their base types.
abstract class Bird {
  abstract void move();
}
class Sparrow extends Bird {
  public void move() {
    System.out.println("Flying");
  }
}
class Ostrich extends Bird {
  public void move() {
    System.out.println("Running");
  }
}

Interface Segregation Principle (ISP)
No client should be forced to depend on methods it doesn't use.
interface Printable {
  void print();
}
interface Scannable {
  void scan();
}
class BasicPrinter implements Printable {
  public void print() {
    System.out.println("Printing...");
  }
}

Dependency Inversion Principle (DIP)
Depend on abstractions, not concrete implementations.
interface Keyboard {
  String input();
}
class MechanicalKeyboard implements Keyboard {
  public String input() {
    return "Mechanical keystrokes";
  }
}
class Computer {
  private Keyboard keyboard;
  public Computer(Keyboard keyboard) {
    this.keyboard = keyboard;
  }
  public void type() {
    System.out.println(keyboard.input());
  }
}

Comments

Popular posts from this blog

PL/SQL

JAVA8 Features

Build Automation