Title: Introduction to Aspect Oriented Programming with Cirrus and Delphi Prism
1Introduction toAspect Oriented Programming with
Cirrus and Delphi Prism
- Jim McKeeth Podcast at Delphi.org
2Agenda
- What is AOP?
- Why AOP?
- Two AOP Paradigms
- The Cirrus Framework
- Examples
- Debugging
- Other AOP Frameworks
- Future
2
3What is Aspect-OrientedProgramming?
?
4A Paradigm Shift
- Aspect-Oriented programming is to
Object-Oriented programming
Object-Oriented programming is to Procedural
programming
as
5A Definition
- A programming paradigm that increases modularity
by enabling improved separation of concerns. This
entails breaking down a program into distinct
parts allowing the separation of cross-cutting
concerns.
Think of it as Super-Encapsulation
6Think of it as Super-Encapsulation
7What is a Concern?
- A distinct and cohesive area of functionality
- Examples
- Business logic
- User interface
- Database access
- Error handling
- Logging
- Threading
- Transactions
- Security
- Exception handling
8What Makes a Concern Cross-Cut?
?
Error handling
Business logic
Thread locking
User Interface
9The Principles of OOD
- SRP The Single Responsibility Principle - A class
should have one, and only one, reason to change. - OCP The Open Closed Principle You should be able
to extend a classes behavior, without modifying
it. - LSP The Liskov Substitution Principle Derived
classes must be substitutable for their base
classes. - ISP The Interface Segregation Principle Make fine
grained interfaces that are client specific. - DIP The Dependency Inversion Principle Depend on
abstractions, not on concretions.
Robert C. Martin Uncle Bob www.objectmentor.com
butUncleBob.com
http//butUncleBob.com/ArticleS.UncleBob.Principle
sOfOod
10Two AOP Paradigms
- Pre-Compile / At-Compile
- Decorating the code with the aspects before
compilation (method used by Cirrus) - Concerns are woven in during compilation.
- Post-Compile
- Weave the advice in after compilation via
Point-Cut definitions (method used by AspectJ) - Allows modification of existing functionality
without modifying code.
11(No Transcript)
12Bank Transfer
method TBank.Transfer(fromAccount, toAccount
TAccount amount Integer) begin if
fromAccount.Balance lt amount then begin
raise new EInsufficientFundsException() end
fromAccount.withdraw(amount)
toAccount.deposit(amount) end
13With Security
With Security
13
14With Logging . . . .
With Threading
With Transactions
With ???
14
15With Cirrus AOP
15
16Cirrus Fundamentals
- Add reference to RemObjects.Oxygene.Cirrus.
- Not necessary to deploy.
- Aspects must be in a separate assembly.
- Also not necessary to deploy.
- Aspects woven in at compile time.
- Cirrus exists as a series of Interfaces
(callbacks). - Aspects are applied via Attributes with the
aspect prefix.
17 18More on Cirrus
- Cirrus Overview
- prismwiki.codegear.com/en/Cirrus_Overview
- Common Aspect Library
- http//code.remobjects.com/p/prismaspects/
- RemObjects Blog
- Blogs.RemObjects.com/blogs/
- My Blogs
- Delphi.org
- DavinciUnltd.com
18
19Other AOP Frameworks
- For Delphi Win32
- MeAOP in MeSDK
- code.google.com/p/meaop/
- Other .NET options
-
- PostSharp.org
-
- SpringFramework.net
- C
- AspectC.org
- Java
- eclipse.org/AspectJ
19
20The Futureof AOP
?
21Contact Me
- Jim McKeeth
- jim_at_mckeeth.org
- Twitter.com/JimMcKeeth
- FriendFeed.com/JimMcKeeth
- Delphi.org
- DavinciUnltd.com/Code/Cirrus/ ? Get the slides