Aspect Programming comes in real handy to solve certain types of software problems
Snowpal Podcast: A quick look at Aspect Programming, what it entails, and when you might be better served taking advantage of it.
In this video, the speaker discusses Aspect Programming, focusing on its applications, benefits, and best practices. They introduce Aspect Programming as a technique used in various programming languages, particularly in Java development with frameworks like AspectJ and Spring aspects. The speaker highlights common applications of Aspect Programming such as logging, performance monitoring, and caching.
Summary
Introduction to Aspect Programming
Definition and significance
Commonly used frameworks like AspectJ and Spring aspects in Java development
Applications of Aspect Programming
Logging, performance monitoring, caching
Examples of how it enhances codebase management and optimization
Use Case: Performance Enhancement
Identifying bottlenecks in a large codebase
Avoiding manual editing of individual methods
Implementing changes outside the essential code layer
Advantages of Aspect Programming
Minimizing impact on existing codebase
Facilitating scoped testing for new changes
Mitigating risks of unintended side effects
Best Practices and Recommendations
Adoption of aspect-oriented design patterns
Caution against direct changes to existing classes or methods
Emphasizing the long-term benefits of aspect-oriented approaches
Podcast
Transcript
0:00
Hey there, in this video, let's talk about Aspect programming, or at least some aspects of Aspect programming.For those of you who are not familiar, you should certainly look it up, but I'm presume a lot of you may have used this at some point of time in your career.If you're a Java developer, you may have used Aspect J or Spring aspects depending on the language of the stack you work on.
0:21
A lot of them support a notion of this.They may call it differently.Sometimes the support may not be the same to the same level, but there is support for aspects in pretty much most of the languages actually.Or if not, you should maybe write it yourself or approach it using a design pattern such as that.
0:40
So let me tell you why I think it's useful and state the more obvious cases too.So when people talk about aspects or point cuts and concerns, it generally means they're using that for logging, for performance monitoring or maybe for caching.
0:55
So let's take some, at least one of those examples right?So you have a lot, you have a large code base, lots of classes, modules, makes sense and what not.And you want to say add, you want to make some performance enhancements, right?And how can you?First you need to figure out where to make those improvements.
1:13
So you're trying to identify the bottlenecks.There are several tools you could do, like even COT solutions let let you get to the bottom of these problems.But let's say once you make some progress there, you want to try to optimize some of these methods or API.What do you do?Right the the most obvious way, not the best way, is editing each and everyone of those methods and adding some changes there specifically.
1:36
You could go take that approach, but except it's going to have you're going to have to do a regression test.You have to go through the whole test suite again, and it touches a lot of your layers, right?The more you touch, the more you're going to break and the more you have to test.Make sure you don't break at all with the aspects.What you do is you don't touch each of those individual methods, but you actually write the code, the essence of the code, elsewhere.
1:59
So be it caching or be it performance monitoring, you do that outside, in a different layer, in a different set of classes, and you wrap these.And I'm using these words loosely.There are there's a specific language for aspects.Please go look it up.Some of them are more abstract than others, but here's the essence.
2:17
You wrap your methods with whatever it is that you want to do.I want to log something at the beginning of the method, or after I exit the method.Or I want to embed some performance sensors in these methods, or I want to cache these API's and I want to invalidate the cache in certain cases and rely on expiration based caching in the other.
2:34
Whatever it is that you're trying to do, you can do all of that outside of your essential code layer that does whatever it is that it's doing right now in terms of features, and then just wrap.And I'm using the word wrap loosely here, so take it to the grain of salt.
2:50
And then you can just wrap these classes and methods with your aspects, meaning everything happens outside so there is no impact to the existing code base.Essentially, so your tests can be scoped to the new changes that you're making, to the, to those performance changes, to those caching changes, and you don't have to worry about breaking existing code.
3:10
Because again, the more you touch, the more you're going to essentially break, like it or not, and the more you're going to have to test.So aspects play a great role there.And even if you're not using a specific aspect, aspects oriented library or a framework, make sure you follow those design patterns in the way you approach the problem.
3:30
So you're essentially doing it kind of using code and code aspects, even if you're not actually using an aspect framework to solving that problem.And I say this because many times I see that you know when you making a change that needs to happen to a lot of your code base, folks actually resort to making changes in those specific classes or methods just because you know, that's that's the easiest place to start doing it.
3:59
But in the long run, you're probably going to regret doing it that way.So just just give this another thought and use aspects at every opportunity that you get.
Thank you.
Snowpal Products
Backends as Services on AWS Marketplace
Mobile Apps on App Store and Play Store
Education Platform for Learners and Course Creators