Welcome to weblogs.com.pk Sign in | Join | Help

AOP: How AOP is Different from Polymorphism and Event Driven Approaches

During the presentation we were asked, how AOP differs from the OOP’s polymorphism concept. Answer is, AOP is all about modularization and it facilitates us by dynamic weaving. Dynamic weaving is a process that weaves the advice code at joint points that are identified automatically using point cuts. The emphasis is “automatically”

 

Though we can simulate this using polymorphism, but we have to call appropriate implementation manually. And this leads to two big problems. A risk of hard to identify bug that may be caused due to the fact that we are required to call the certain piece of code at multiple locations, and we may forget to call it at some. The other problem is the messiness that is created due to these inline calls, the core concern code gets harder to understand and hence maintenance cost increases. AOP assures us that if point cuts are properly defined, the aspect’s advice code will automatically be weaved into the core method.

 

I would also like to take this opportunity to point out that similar points hold for the event driven approaches, where events are required to manually raise, and the client code is required to assure the weaving is properly done. Consider the following example. (Syntax may not be correct)

 

class BusinessRules

{

            public event SecretOperationCalled(User);

            public void SecretOperation(User user)

            {

                        raise SecretOperationCalled(user);

                        //Core Concern

            }

}

 

class SomeController

{

            BusinessRules rule = new BusinessRules;

            void SecuriyChecks(User user);

            {

                        //Check user

                        //Throw Exception if not allowed

            }

            void SecretOperationLogging(User user);

            {

                        //Log Activity

            }

            void main()

            {

                        rule.SecretOperationCalled += SecurtyChecks;

                        rule.SecretOperationCalled += SecretOperationLogging;

                        rule.secretOperation();

            }

}

Published Tuesday, October 19, 2004 12:19 PM by khurram
Filed under: ,

Comments

No Comments

New Comments to this post are disabled