DEV Community

Rajat Parashar
Rajat Parashar

Posted on

Imperative vs Declarative, S.O.L.I.D and AOP(Aspect-oriented programming)

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(Aspect Oriented Programming)

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 for more details.

Imperative vs Declarative Programming

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

To illustrate even further, 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.

S.O.L.I.D Principles

  • 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(Robert C. Martin).

Read more here

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

Top comments (0)