Beruflich Dokumente
Kultur Dokumente
Prepared by Ryan
Outline
Enterprise Application Architecture
Layering Structure
Domain Logic
C# Attribute
CUHK Student
College
Enterprise Application
Architecture
O/R Mapping Problems – Inheritance
Single Table Inheritance
Name School Class Department College
Class
Department
College
Reflection
Querying information at run-time
Dynamically invoking methods
C# Attribute
Intrinsic Attribute
Built-in attributes in .NET Common Library
Runtime (CLR)
Examples
In your assignment 1
[assembly: AssemblyVersion(“1.0.0.0”)]
[serializable]
[STAThread]
C# Attribute
Custom Attribute
Create your custom attribute Use your custom attribute
// Set what kinds of elements can use this custom attribute [MyAttribute("MyClass")]
[AttributeUsage(AttributeTargets.All)] public class Test {
public class MyAttribute : Attribute { // Define your own attribute [MyAttribute("MyMethod")]
string myName; public void Print {
Console.WriteLine("Test
public MyAttribute(string name) { Program");
myName = name; }
} }
Output
Test Program
Aspect Oriented Programming
OOP
Breaking down a complex system into modules
Encapsulating responsibilities into different
objects
Problems
Some tasks cut across multiple modules
(crosscutting concern)
Logging
Authentication
Solution: Aspect Oriented Programming (AOP)
Aspect Oriented Programming
AOP in C#
Non-AOP Implementation AOP Implementation
[Log]
public class Test : ContextBoundObject {
public void TestMethod() {
Console.WriteLine("Test Method");
}
}
Aspect Oriented Programming
How does it work in C#
“ContextAttribute” and “ContextBoundObject”
Intercepting the calls(Interception)
Client YourObject
Without Interception
Intercepted by .NET
Transparent Message
Client YourObject
Proxy Sink
With Interception
References
Enterprise Application Architecture
M. Fowler, “Patterns of Enterprise Application
Architecture”, Addison Wesley
C# Attribute
http://www.oreilly.com/catalog/progcsharp/chapter/ch1
Aspect Oriented Programming (AOP)
http://www.codeproject.com/gen/design/aop.asp
http://msdn.microsoft.com/msdnmag/issues/02/03/AOP