Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

Going Beyond OO Using Aspect-Oriented Programming

Object-oriented (OO) techniques are built upon the principle that like responsibilities and concerns can be cohesively grouped together and encapsulated into one entity — such as a class. However, some responsibilities cannot be encapsulated using the standard techniques available in OO languages. These responsibilities are called crosscutting concerns because they "cut across" multiple parts of a program. Logging is such a crosscutting concern because you must implement logging in every part of the system. However, the only way to make sure every system component logs itself, and in a standard way, is to manually insert code where appropriate.

Aspect-oriented programming (AOP) tools allow you to specify in one place in your program how you plan to address a crosscutting concern. The tools then generate the implementation and insert it into all the necessary places in your code.

The following example shows the use of AOP in the implementation of a stack.

aspect AddLogging {
  - push(ItemType* item)  {
    AddLogging.info(@"Pushing item", item)
  }
- (ItemType *) pop  {
    AddLogging.Info (@"Popping item", returnedItem);
  }
  // Other crosscutting code.
}
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.