1 / 21

IEG3080 Tutorial 11

IEG3080 Tutorial 11. Prepared by Ryan. Outline. Enterprise Application Architecture Layering Structure Domain Logic C# Attribute Aspect Oriented Programming (AOP). Enterprise Application Architecture. Complex systems always break down into layers e.g. Networking – OSI 7 layers Model

valora
Download Presentation

IEG3080 Tutorial 11

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IEG3080 Tutorial 11 Prepared by Ryan

  2. Outline • Enterprise Application Architecture • Layering Structure • Domain Logic • C# Attribute • Aspect Oriented Programming (AOP)

  3. Enterprise Application Architecture • Complex systems always break down into layers • e.g. Networking – OSI 7 layers Model • Pros • Working on a single layer without knowing much about other layers • Minimizing dependencies between layers • Con • Transforming from layers harming performance

  4. Enterprise Application Architecture • Enterprise Application Architecture – 3-layer • Presentation Layer • Display of information e.g. GUI windows, webpage • Handling user commands • Domain Logic Layer • Business logic (Core) • Data Source Layer • Communication with database, messaging systems

  5. Enterprise Application Architecture • Domain Logic Patterns • Domain Model • An object model of the domain that incorporates both behavior and data • Solving the problem in object-oriented way • Pro – Handling complex logic in a well-organized way • Con – “Impedance mismatch” between OO model and relational database

  6. Enterprise Application Architecture • O/R Mapping Problems – Identity Problem • OO – Different objects referenced by different pointers • Database – Different rows identified by primary key • Solutions • Identity Field Key Identity Field public class Team { int TeamID; string TeamName; }

  7. Team Team ID Team Name Player Player ID Player Name Enterprise Application Architecture • O/R Mapping Problems – Identity Problem • Solutions (Cont’d) • Foreign Key Mapping 1 * Foreign Key Mapping

  8. Student Name School University Student Department Secondary Student Class CUHK Student College Enterprise Application Architecture • O/R Mapping Problems – Inheritance How to do mapping?

  9. Enterprise Application Architecture • O/R Mapping Problems – Inheritance • Single Table Inheritance • Wasting space – many null columns • Concrete Table Inheritance • Changing the superclass  altering all the subclasses’ tables

  10. Enterprise Application Architecture • O/R Mapping Problems – Inheritance • Class Table Inheritance • Requiring multiple joins to rebuild an object

  11. Enterprise Application Architecture • Solutions • OO databases • Not common (relational databases are widely adopted) • Tight coupling with the domain model • Automated O/R mapping tools • Not prefect (may solve 80% of the problems) • Expensive

  12. Enterprise Application Architecture • Other Domain Logic Patterns • Transaction Scripts • Organizes business logic by procedures where each procedure handles a single request from the presentation • Server page (php, jsp), CGI scripts • Table Module • A single instance that handles the business logic for all rows in a database table or view • Commonly use in .NET development platform

  13. C# Attribute • C# Attribute • Embedding information in C# code • Placed in square brackets [ ], above an Attribute Target (e.g. class, field or method) • Reflection • Querying information at run-time • Dynamically invoking methods [serializable] public class Test { … }

  14. 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]

  15. C# Attribute • Custom Attribute Use your custom attribute [MyAttribute("MyClass")] public class Test { [MyAttribute("MyMethod")] public void Print { Console.WriteLine("Test Program"); } } Create your custom attribute // Set what kinds of elements can use this custom attribute [AttributeUsage(AttributeTargets.All)] public class MyAttribute : Attribute { // Define your own attribute string myName; public MyAttribute(string name) { myName = name; } public string Name { get { return myName; } } }

  16. C# Attribute • Reflection – Querying information public class MyProgram { public static void Main() { Type type = Type.GetType("Test"); foreach (Attribute attr in type.GetCustomAttributes(false)) { // Retrieve attributes for the class MyAttribute myattr = attr as MyAttribute; if (myattr != null) Console.WriteLine(attr.Name); } foreach(MethodInfo method in type.GetMethods()) { foreach (Attribute attr in method.GetCustomAttributes(false)) { // Retrieve attributes for the method MyAttribute myattr = attr as MyAttribute; if (myattr != null) Console.WriteLine(“Method: {0} with Attribute: {1}”, method, attr.Name); } } } } Output MyClass Method: Void Print() with Attribute: MyMethod

  17. C# Attribute • Reflection – Invoking methods public class MyProgram2 { public static void Main() { Type type = Type.GetType("Test"); Object o = Activator.CreateInstance(type); // Create a “type” object MethodInfo mi = type.GetMethod("Print"); mi.Invoke(o, null); // Invoke method - “mi” } } Output Test Program

  18. 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)

  19. Aspect Oriented Programming • AOP in C# Non-AOP Implementation public class Test { public void TestMethod() { Log log = new Log(); log.Print("Enter"); // Log when entering this method Console.WriteLine("Test Method"); log.Print("Leave"); // Log with leaving this method } } AOP Implementation [AttributeUsage(AttributeTargets.Class)] public class LogAttribute : ContextAttribute { // Code Here } public class LogProperty : IContextProperty, IContributeObjectSink { // Code Here } public class LogAspect : IMessageSink { // Code Here } [Log] public class Test : ContextBoundObject { public void TestMethod() { Console.WriteLine("Test Method"); } }

  20. Aspect Oriented Programming • How does it work in C# • “ContextAttribute” and “ContextBoundObject” • Intercepting the calls(Interception) Client YourObject Without Interception Intercepted by .NET Transparent Proxy Message Sink Client YourObject With Interception

  21. References • Enterprise Application Architecture • M. Fowler, “Patterns of Enterprise Application Architecture”, Addison Wesley • C# Attribute • http://www.oreilly.com/catalog/progcsharp/chapter/ch18.html • Aspect Oriented Programming (AOP) • http://www.codeproject.com/gen/design/aop.asp • http://msdn.microsoft.com/msdnmag/issues/02/03/AOP/

More Related