Most Common Design Patterns Concept: What are SOLID, DRY and ACID principles – Part 2

ACID principles

Atomicity

  • Definition: A transaction is an all-or-nothing operation. Either every step in the transaction is completed successfully, or none of it happens.

example:

Bank Transfer: When transferring $100 from Account A to Account B, either:$100 is deducted from Account A and added to Account B, or no money is transferred at all. There cannot be a situation where money is deducted from one account but not added to the other.

Consistency

  • Definition: A transaction must bring the database from one valid state to another, maintaining all rules and constraints.

example:
E-commerce Inventory
: When an item is sold, the inventory count must decrease. If the count goes negative, the database is in an invalid state.

Isolation

  • Definition: Transactions should not interfere with each other. The results of a transaction should not be visible to others until it is complete.

example:

Movie Ticket Booking: If two users are booking the last available seat, the database ensures only one transaction succeeds, preventing overselling.

Durability

  • Definition: Once a transaction is committed, its changes are permanent, even if the system crashes.

example:

Online Order Placement: When an order is confirmed, it remains confirmed even if the server goes down right afterward.

Press enter or click to view image in full size

ACID remember Summery

IOC

Inversion of Control (IOC) is a design principle in software development that means you reverse the way control is typically managed in a program. Instead of your code controlling the flow, it hands over that control to a framework or another system. This makes the program more flexible, modular, and easier to test.

Example:

Think of a restaurant’s kitchen:

  • Without IOC: The manager constantly tells each chef what to cook and when.
  • With IOC: The manager hands over control to a kitchen supervisor, who ensures everything is prepared as per orders.

Key Benefits of IOC

Decoupling: Components don’t need to know how other components work; they just rely on the framework to connect them.
Flexibility:Easier to swap out or update components without affecting others.
Testability: Components can be tested independently because they don’t directly depend on each other.

IOC in Frameworks

Spring Framework (Java):
Uses IOC to manage dependencies automatically through a container.
Example: You define beans (components) and let the framework inject dependencies.

Django (Python):
The framework decides how views, models, and templates are connected.

Angular (JavaScript):
Uses Dependency Injection (a form of IOC) to inject services into components.

Ref:https://medium.com/@kushanpeiris1118/most-common-interview-concept-what-are-solid-dry-and-acid-principles-937ca2945977

Leave a Reply

Your email address will not be published.