SOLID / DRY principles

In software development, Object-Oriented Design plays a crucial role when it comes to writing flexible, scalable, maintainable, and reusable code. There are so many benefits of using OOD but every developer should also have the knowledge of the SOLID principle for good object-oriented design in programming. The SOLID principles are designed to help developers design robust, maintainable applications. The five SOLID principles are: Single-responsibility principle - Function and classes should have one job. Open–closed principle - Classes and functions should be open for  extension but not for modification. Liskov substitution principle - Child class can replace parent class Interface segregation principle - This principle is the first principle that applies to Interfaces instead of classes in SOLID and it is similar to the single responsibility principle. It states that “do not force any client to implement an interface which is irrelevant to them“. Here your main goal is ...

Difference between localStorage and sessionStorage

Both `localStorage` and `sessionStorage` are web storage options provided by modern web browsers to store data on the client-side. They have some similarities but also important differences in terms of data persistence and scope. Here's a breakdown of the key differences:


1. Data Persistence:

   - `localStorage`: The data stored in `localStorage` persists even after the browser window is closed and reopened. It remains available until explicitly cleared or removed.

   - `sessionStorage`: The data stored in `sessionStorage` persists only for the duration of the current browser session. When the browser window or tab is closed, the data is cleared and no longer accessible.


2. Scope:

   - `localStorage`: The data stored in `localStorage` is accessible across multiple windows or tabs of the same origin. This means that data set in one window/tab can be accessed in another window/tab of the same origin.

   - `sessionStorage`: The data stored in `sessionStorage` is limited to the specific window or tab in which it was set. It is not accessible by other windows or tabs of the same origin.


3. Storage Limit:

   - `localStorage`: The maximum storage limit for `localStorage` is typically larger (typically around 5-10MB) compared to `sessionStorage`.

   - `sessionStorage`: The storage limit for `sessionStorage` is usually smaller (typically around 5-10MB) compared to `localStorage`.


4. Data Sharing:

   - `localStorage`: The data stored in `localStorage` is shared among all frames and iframes under the same origin. This means that if an iframe or frame accesses `localStorage`, it will have access to the same data as the parent window.

   - `sessionStorage`: The data stored in `sessionStorage` is not shared with iframes or frames. Each iframe or frame will have its own separate `sessionStorage`.


5. Automatic Clearing:

   - `localStorage`: The data in `localStorage` persists until explicitly cleared by the user or through code.

   - `sessionStorage`: The data in `sessionStorage` is automatically cleared when the browser session ends, which occurs when the window or tab is closed.


Both `localStorage` and `sessionStorage` provide a simple key-value storage mechanism and are accessed using the same JavaScript APIs (`localStorage.setItem()`, `localStorage.getItem()`, etc.) with minor differences in syntax. They are useful for storing temporary or semi-persistent data on the client-side, depending on the specific requirements of your web application.

Comments

Popular posts from this blog

Scope in javascript

What is memoization