Aspect-oriented Programming

By Tomás Cordara, EDRANS Backend developer

At EDRANS we did a hackathon with the purpose of designing a service layer that would act as a wrapper of an HTTP client and would add extra behavior to it. Cool, uh?

In the end, the organizer of the hackathon showed the development team a solution implemented in Ruby that gives the service layer extra behavior but without changing its implementation, using ideas from Aspect-Oriented Programming, specifically the Decorator Pattern:

Hello there, Decorator Pattern

A Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects.

With this idea in mind… I started thinking about how would I implement that idea with the languages that I commonly use: TypeScript and C#

In TypeScript, by turning on a compiler flag called “experimentalDecorators

We can write code that looks like this

Where we can write a particular search functionality, and add extra behavior to it via decorators.

These decorators are going to be applied every time the function is called and would live in the same context of that function.

Measure Elapsed Time

Memoization

MaxLimitCalls

C#

The same idea could be implemented over an ASP.NET API endpoint. In C#, attributes can be placed on almost any declaration, and they are used by the internal teams at Microsoft to build features for platforms:

MeasureElapsedTime

MaxLimitCalls

Memoization

Want to join our Software Development Team?

Drop us an email at opportunities@edrans.com or check our Career page by clicking here.

--

--

We are an AWS Premier Consulting Partner company. Since 2009 we’ve been delivering business outcomes and we want to share our experience with you. Enjoy!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
EDRANS Stories

We are an AWS Premier Consulting Partner company. Since 2009 we’ve been delivering business outcomes and we want to share our experience with you. Enjoy!