Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Ramon Kleiss:
Introduction to Aspect-Oriented Programming
Aug 07, 2014 @ 16:09:10

Ramon Kleiss has posted a tutorial to his site recently introducing you to the concept of AOP in PHP (Aspect Oriented Programming). In it he provides an overview of some of be basic AOP concepts and code examples showing them in action.

For my first blog post, I'm going to take you on a little trip into a really cool programming paradigm: aspect-oriented programming, which is a little known style of programming while it can come in really useful. It is common knowledge that in software development you should have a Separation of Concerns (the first letter in SOLID). Although it is accepted that the Single Responsibility Principle is hard to design, it is still valued as one of the top best practices one can use.

He starts with a base class (ArticleManager) and how it's easy for it to grow when more dependencies are needed. He then evolves this example to use a more AOP approach, resolving the scope creep in the main class using cross-cutting concerns, advice, pointcut and aspects. He moves away from his basic example and uses a Symfony-based example to show how to implement a LoggingPointcut, inject it into the class and set up an "intercept" method to handle the notification of which method was called.

You will have to be careful to remember that you are using AOP as the application development continues, since it is very easy to forget about if you're happily developing away. Just take this rule of thumb: does the class I'm modifying care about the extra functionality? If it doesn't see if you can use inheritance or see if you can use AOP.
tagged: aspect oriented programming aop introduction example

Link: http://ramonkleiss.nl/intro-to-aop/


Trending Topics: