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

Evert Pot's Blog: HTTP Basic and Digest authentication with PHP

Etienne Kneuss' Blog: Late Static Bindings Explained

Stefan Mischook's Blog: Object Oriented PHP Tutorial in PDF

David Stockton's Blog: Zend JSON - An Introduction

Court Ewing's Blog: A Simple Alternative to Global Registry Dependency


Community Events





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


opinion tips community update laravel zendserver symfony series library podcast deployment release package introduction interview install api list language framework

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