News Feed
Sections




News Archive
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
August 07, 2014 @ 11: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.
0 comments voice your opinion now!
aspect oriented programming aop introduction example

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

blog comments powered by Disqus

Similar Posts

PHPImpact Blog: Loading models within modules in the Zend Framework

IBM developerWorks: PHP frameworks, Part 1: Getting started with three popular frameworks

Sebastian Bergmann\'s Blog: Current State of AOP for PHP

SitePoint PHP Blog: What to Expect from Yii 2.0

Cormac's Blog: Read-only object variables in php using magic methods


Community Events

Don't see your event here?
Let us know!


development library introduction opinion api community release podcast psr7 interview conference framework laravel5 extension unittest voicesoftheelephpant series language laravel wordpress

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework