Aspect-Oriented Programming vs. Object-Oriented Programming

Instructor: Martin Gibbs

Martin has 16 years experience in Human Resources Information Systems and has a PhD in Information Technology Management. He is an adjunct professor of computer science and computer programming.

Entire programming languages (Java) have been built around object-oriented programming methods. Both technology and methodologies evolve, spawning new ideas and methods. This lesson compares a new methodology (aspect-oriented programming) against object-oriented programming.

Aspect-Oriented Programming: A Better Mousetrap?

Not only is it a new technology, but we get a new acronym to boot! AOP, or Aspect-Oriented Programming was built as a response to limitations of Object-Oriented Programming (OOP).

Object-Oriented Programming (OOP)

Object-Oriented Programming (OOP) is a model for software development that is focused on objects and classes.

A class is a blueprint for something, e.g., engine, publication, employee, etc... An object is an instance of that class. Engine is generic; a Hemi is an instance of the Engine class. A class can also inherit methods and variables from another class. This is called inheritance. It is therefore possible to build a program with a fairly complex hierarchy of classes.

Even though you may have a large family tree of classes in your program, the beauty of OOP is that each one serves its own purpose. You can protect data and variables within the classes - you don't give the radio access to the engine. But you can give the engine access to the drive shaft. The technical term for this type of data hiding/data protection is encapsulation.

There is a drawback to all of this, however. What if you have a behavior that crosses several classes? For example, log files or a monitoring routine. This routine would need to run on many classes. Let's say we needed to monitor almost 90% of the car: Engine systems, cooling, exhaust, drive train, etc. We'd have to add the monitor to almost every class or method! This type of behavior crosscuts a wide array of classes, much like a diagonal street. OOP comes up short in this aspect.

Aspect-Oriented Programming (AOP)

Aspect-Oriented Programming (AOP) helps to provide a solution to the previous problem. Instead of objects, AOP deals with aspects. An aspect is a behavior that cuts through multiple objects.

One of the drawbacks to OOP is that certain things will crosscut objects and methods. That is, a single behavior will apply to multiple classes. An example is logging or monitoring; you would want to monitor/log updates to several classes in a financial program. In OOP, you have to add the logging to each class or method. AOP avoids this by treating this crosscutting behavior as an aspect, as opposed to an object.

These aspects are defined separately from the main code. When you want to run the logging routine, you set a pointcut, or place in the code where you run the code. This could be in a class or method. By having a single block of code to deal with the aspect, you greatly reduce the redundancy that comes with crosscutting behavior.


Although OOP still maintains a huge footprint in the programming landscape, its shortcomings (the crosscutting issue) has led to the development of AOP. You can still have an OOP program, with the behaviors added as wrappers to your code.

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account