What is cross cutting in AOP

Q

What is cross cutting in AOP ?

✍: Guest

A

When one or many concerns span across module it is called as cross cutting. Example in our audit trail example we will probably need to audit trail for customer as well as supplier. So Audit trail can span across other objects also that is termed as cross cutting. Below are both the classes actually implemented as per class diagram 8.7. If you see the “Update” method of the customer class, its doing both of the concerns that is checking for customer code length and also maintaining the audit trail using the audit trail class.

Public Class ClsCustomer
Private pstrCustcode As String
Private pstrCustName As String
Public Property Code() As String
Get
Return pstrCustcode
End Get
Set(ByVal Value As String)
pstrCustcode = Value
End Set
End Property
Public Property CustomerName() As String
Get
Return pstrCustName
End Get
Set(ByVal Value As String)
pstrCustName = Value
End Set
End Property
Public Function Update() As Boolean
‘ first / core concern
If pstrCustcode.Length() > 10 Then
Throw New Exception("Value can not be greater than 10")
End If
' usingthe customer audit trail to do auditing
‘ second concern / system concern
Dim pobjClsAuditTrail As New ClsAuditTrail
With pobjClsAuditTrail
.NewValue = "1001"
.OldValue = "1003"
.UserName = "shiv"
.Update()
End With
' then inserting the customer in database
End Function
End Class
Public Class ClsAuditTrail
Private pstrUserName As String
Private pstrOldValue As String
Private pstrNewValue As String
Private pdblLogTime As Double
Public Property UserName() As String
Get
Return pstrUserName
End Get
Set(ByVal Value As String)
pstrUserName = Value
End Set
End Property
Public Property OldValue() As String
Get
Return pstrOldValue
End Get
Set(ByVal Value As String)
pstrOldValue = Value
End Set
End Property
Public Property NewValue() As String
Get
Return pstrNewValue
End Get
Set(ByVal Value As String)
pstrNewValue = Value
End Set
End Property
Public Property LogTime() As Double
Get
Return pdblLogTime
End Get
Set(ByVal Value As Double)
pdblLogTime = Value
End Set
End Property
Public Sub Update()
' do the logging activity here
End Sub
End Class

This is achieved at this moment in .NET using attribute programming. Here is the change to the customer class

Imports System.Reflection
Public Class ClsCustomer
Private pstrCustcode As String
Private pstrCustName As String
Public Property Code() As String
Get
Return pstrCustcode
End Get
Set(ByVal Value As String)
pstrCustcode = Value
End Set
End Property
Public Property CustomerName() As String
Get
Return pstrCustName
End Get
Set(ByVal Value As String)
pstrCustName = Value
End Set
End Property
<ClsAuditTrail("Shiv", "1001", "1003", 12)> _
Public Function Update() As Boolean
If pstrCustcode.Length() > 10 Then
Throw New Exception("Value can not be greater than 10")
End If
' usingthe customer audit trail to do auditing
' then inserting the customer in database
End Function
End Class
And here is the change to the audit trail class
Imports System.Reflection
 _
Public Class ClsAuditTrail
Inherits Attribute
Private pstrUserName As String
Private pstrOldValue As String
Private pstrNewValue As String
Private pdblLogTime As Double
Public Property UserName() As String
Get
Return pstrUserName
End Get
Set(ByVal Value As String)
pstrUserName = Value
End Set
End Property
Public Property OldValue() As String
Get
Return pstrOldValue
End Get
Set(ByVal Value As String)
pstrOldValue = Value
End Set
End Property
Public Property NewValue() As String
Get
Return pstrNewValue
End Get
Set(ByVal Value As String)
pstrNewValue = Value
End Set
End Property
Public Property LogTime() As Double
Get
Return pdblLogTime
End Get
Set(ByVal Value As Double)
pdblLogTime = Value
End Set
End Property
Public Sub New(ByVal pstrUserName As String, _
ByVal pstrOldValue As String, _
ByVal pstrnewValue As String, _
ByVal plng As Long)
Update()

2007-10-24, 5336👍, 0💬