Reputation: 6709
I am familiar with the term: Separation of Concerns. It's pretty much advocating modularity in your code.
However, when I was reading about AOP, it specifically says that it allows you separate cross-cutting concerns.
So my question is, if AOP separates cross-cutting concerns, what kind of concerns does OOP separate?
Upvotes: 0
Views: 65
Reputation: 1180
The short answer: OOP separates abstraction levels. Well-designed OOP code will use a consistent set of abstractions throughout a module.
Long answer: OOP is built on four 'pillars':
These allow a programmer to easily build layers of abstraction, each level using the lower abstractions to provide higher abstractions.
For example, you can build a TCP/IP stack from frames, messages, routing and sessions (Abstractions). When using a session, you do not need to know about how frames are resent, and collision detection (encapsulation). Also, you can send a message without knowing if you are using IP4 or IP6 (polymorphism). And all levels can use the same CRC checking through e.g. inheritance. So these 4 pillars together allow a way of programming where very clean abstraction levels can be created. But all too often, OOP software becomes a mess where the abstraction levels are not cleanly separated.
AOP is complementary to OOP. OOP is focussed on abstraction levels and structures, AOP is focussed on behavior related to 'concerns'. They are orthogonal ways of looking at code.
Upvotes: 0
Reputation: 64943
OOP separates concerns that in a real-world scenario would be coupled each other with direct associations.
For example, a company has many employees, and employees have a salary.
AOP is about concerns that aren't direct associations but more like sentinels that go beyond object to object relationships.
A typical sample scenario for AOP is logging. Logging is still represented by an object called Logger but actually the logging action is like an observer that filters out the normal flow and extracts information intercepting the flow behind the scenes.
While logging can be implemented without AOP, actually you end up dirtying your code with something that has nothing to do with the purpose of a given action (for example: register an user has nothing to do with logging).
Therefore, you should understand that AOP enforces and improves a good separation of concerns, even taking some requirements out of your eyes, keeping the code simpler.
Upvotes: 2