Imperative vs Declarative, S.O.L.I.D and AOP(Aspect-oriented programming)
Tags: learning, programming, daily
Published: 2020-01-04 19:32:22

---
title: Imperative vs Declarative, S.O.L.I.D and AOP(Aspect-oriented programming)
published: true
description: This is going to be a simple post series that will briefly explain some of the programming concepts that I have learned on a particular day.
tags: learning, programming, daily
series: [What I learned Today]
---

### My Introduction
I am a Software Engineer at one of the Retail based startups. This is my first job which I am following since June 2018. This series will be used as a scratchpad for my learning.

### Let's dive in

##### Table Of Contents
  * [AOP](#aop)
  * [Imparative vs Declarative](#imp-dec)
  * [SOLID](#solid)

# AOP(Aspect Oriented Programming) <a name="aop"></a>

AOP is all about dividing parts of software into small modules. Adhering to AOP means separating various cross-cutting concerns of your software into small aspects that provide advice to your procedures(functions). In this way, we can apply extra functionality to our app without changing the codebase.

Crosscutting concerns can be:-
- Background sync
- Security
- Logging
- analytics
- etc

All of the above tasks are not part of business logic(code which resembles the Idea of your app). These come under extra work. So If we have to change the code and invoke the above-mentioned tasks manually then it will resource consuming.

AOP gives us an idea of how can we shortcut these tasks.

#### AOP Terminology 

Under AOP, various aspects advise your code. Aspects are the key unit of modularity.

- *Aspects* - these are the classes or modules that apply some advice to your code. For eg - log every action in your app.
- *Weaving* - weaving is the process of linking the advice to advised object.
- *Advice* - It is a specific job which is done by aspects.

There are various types of advice-
* After
* Before
* Around
* AfterRunning
* AfterThrowing 

Yes, they work as they sound. [Go over reference](#ref) for more details.

# Imperative vs Declarative Programming <a name="imp-dec"></a>
 
As one-liner,Imperative Programming is all about telling the machine the path to follow for achieving something.In this case, machine itself does not know how to reach to a target, we tell it how.
Ex - Assembly language, C++

Conversely in Declarative Programming, we ask the machine what do we need machine does some internal magic and give us what we wanted. We have to explain the objective to machine.
Ex- HTML, SQL

[a good explanation using SQL language](https://www.databasejournal.com/sqletc/article.php/1408491/Beginning-SQL-Programming-Pt-2.htm)

<blockquote style="background: white; color: black;"> To illustrate even further,<i> with imperative code you describe how to do what you want done. Conversely, declarative code enables you to describe what you want to do without worrying about how.</i></blockquote>

# S.O.L.I.D Principles <a name="solid"></a>

 * Single responsibility Principle.
 * Open-closed Principle
 * Liskov Substitution Principle
 * Interface Segregation Principle
 * Dependency Inversion Principle

S.O.L.I.D stands for **first five object-oriented design** by [Uncle Bob] (https://en.wikipedia.org/wiki/Robert_Cecil_Martin)(Robert C. Martin).

Read more [here](https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design)

###Conclusion

AOP is an important concept that every Intermediate programmer should know. SOLID are very important concepts for becoming an expert coder.
Understanding the difference between Imperative and Declarative will make your life easier as a Frontend Developer. 

### References <a name="ref"></a>
- [https://www.geeksforgeeks.org/aspect-oriented-programming-and-aop-in-spring-framework/](https://www.geeksforgeeks.org/aspect-oriented-programming-and-aop-in-spring-framework)

- [https://codeburst.io/declarative-vs-imperative-programming-a8a7c93d9ad2](https://codeburst.io/declarative-vs-imperative-programming-a8a7c93d9ad2)

- [https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design](https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design)
- [https://www.telerik.com/blogs/three-ds-of-web-development-1-declarative-vs-imperative](https://www.telerik.com/blogs/three-ds-of-web-development-1-declarative-vs-imperative)