CSE 136 - Lecture 5 Part 1
What is Business Logic Layer
What is Business Logic Layer 2   Services       exposing business logic to outside system       GPA system can provide ...
Business Layer Patterns   Procedure Pattern           1980s       Transcript Script pattern - A collection of procedures...
Procedure Pattern   Map your business components directly onto    required user actions.   Best suited for simple scenar...
Table Module Pattern   Remember DataSet    in DAL (ADO.NET)        Built-in in ASP.NET   Series of transaction    groupe...
Table Module Pattern 2   Whats wrong with this    Pattern?   You must wait for SQL    stored procedures to    finish   ...
Object-based Pattern - ActiveRecord Pattern   Active Record Pattern is based on DataSet    design but create class object...
Object-based pattern - Active RecordPattern ex
Object-Based Patterns - Domain ModelPattern   Domain Model is also known as Object-    Oriented Design   Define the enti...
Compare the Patterns
Domain Model to ER (DAL)
Class Objects Design - steps   Start with use case diagram   Run thru activity diagram to identify entities    and high-...
UML Review 1
UML Review 2
Domain Model – class diagramex1                Database ER diagram is hidden away                From the Domain Model    ...
Domain Model – class diagramex2         Review table in the database may have         a order_id, but in Domain Model, it ...
Domain Model – class diagramex3               Database ER diagram will have more               tables to stored these info...
Domain Model – class diagramex4
Break Time
CSE 136 - Lecture 5 Part 2
Why use Design Patterns   Provide a starting point for a solution   Speed up productivity in a team   Improves system a...
Object-oriented Design Patterns   Creational     The creational patterns aim to separate a system from      how its obje...
Creational Patterns   Factory   Singleton   Prototype (skip)   Abstract Factory (skip)   Builder (skip)
Creational - Factory example                        Logging C# example                        available on class          ...
Creational - Factory
Creational - Singleton
Creational - Singleton Code                    C# interview question
Structural Design Patterns   Decorator   Proxy   Adapter   Facade   Bridge (skip)   Composite (skip)   Flyweight (s...
Structural - Decorator example
Structural - Decorator                         .NET libraries are                         based on decorator              ...
Structural - Proxy example
Structural - Proxy
Structural - Adapter example
Structural - Adapter
Structural - Facade
Behavioral Pattern   Strategy   Chain of Responsibility   Iterator (skip - you have seen this in C#    lecture “enumera...
Behavioral - Strategy example                       Polymorphism
Behavioral - Strategy                        Polymorphism     Client may come     From GUI
Behavioral - Chain example                  Polymorphism
Behavioral - Chain                     Polymorphism
Review question   Why does domain model a better pattern at the    end?   What are the three categories of OO design    ...
Demo Code   Business Logic Layer   Domain Objects   Error Logging implementation (factory pattern)   Data Transfer Obj...
Your Assignment   Due next Thursday   Design and develop business layer based on    UML     UML  class diagram for Doma...
References   .NET : Architecting Applications for the    Enterprise   Design Patterns: Elements of Re-usable    Object-O...
Upcoming SlideShare
Loading in …5
×

Day5

361 views
233 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
361
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Day5

  1. 1. CSE 136 - Lecture 5 Part 1
  2. 2. What is Business Logic Layer
  3. 3. What is Business Logic Layer 2 Services  exposing business logic to outside system  GPA system can provide graduation status for students Entities  Students taking courses. Courses have schedules and location.  Courses are categorized by departments. Rules, Calculations  Students can only register 20 units maximum per quarter  CSE136 must be taken after CSE135, etc. Validation Cannot rely JavaScript for validation  Is the social security # 9 digits?  Is credit card all digits?
  4. 4. Business Layer Patterns Procedure Pattern 1980s  Transcript Script pattern - A collection of procedures (steps of execution). Table Module Pattern 1990s  similar to transaction script but operations are grouped by data (dataSet/dataTable) Object-based Pattern 21th century  Interrelated & Interconnected objects.  Active Record Pattern - record looks like data tables from the database with additional methods()  Domain Model Pattern - not ER diagrams, but OOD diagrams
  5. 5. Procedure Pattern Map your business components directly onto required user actions. Best suited for simple scenarios and unlikely changing spec Simple and no start-up cost Can not handle large/complex specs As complexity grow, becomes more costly (not easily extended) CSE 136 will NOT use this design pattern
  6. 6. Table Module Pattern Remember DataSet in DAL (ADO.NET) Built-in in ASP.NET Series of transaction grouped by Data Grouping the info/table by how data are related Good for quick presentation display
  7. 7. Table Module Pattern 2 Whats wrong with this Pattern? You must wait for SQL stored procedures to finish If SQL proc changes, it changes the BL structure  remove a column  changed a column name  You cant catch this error through unit
  8. 8. Object-based Pattern - ActiveRecord Pattern Active Record Pattern is based on DataSet design but create class object for each DataTable. Duplication and quite a hassle Better than Table Module Pattern  SQL Proc changes wont affect outcome One step closer to Object Oriented Design, but not object-oriented yet
  9. 9. Object-based pattern - Active RecordPattern ex
  10. 10. Object-Based Patterns - Domain ModelPattern Domain Model is also known as Object- Oriented Design Define the entities and the relationships & flows between them Each Entity has data (variables) & behavior (methods) Consider the issues of “coupling” and “cohesion”. “Reuse”, “Maintainability”, and “Extensibility” A diagram can be really large (divide & conquer) More Object-oriented design using Design
  11. 11. Compare the Patterns
  12. 12. Domain Model to ER (DAL)
  13. 13. Class Objects Design - steps Start with use case diagram Run thru activity diagram to identify entities and high-level relationship Run thru sequence diagram again to identify attributes and methods for each entities.  You may skip this step for 136 to save time
  14. 14. UML Review 1
  15. 15. UML Review 2
  16. 16. Domain Model – class diagramex1 Database ER diagram is hidden away From the Domain Model How many tables to store student info?
  17. 17. Domain Model – class diagramex2 Review table in the database may have a order_id, but in Domain Model, it is not used.
  18. 18. Domain Model – class diagramex3 Database ER diagram will have more tables to stored these information (vehicle, make, model, vendor, produc t, location, back_order, etc).
  19. 19. Domain Model – class diagramex4
  20. 20. Break Time
  21. 21. CSE 136 - Lecture 5 Part 2
  22. 22. Why use Design Patterns Provide a starting point for a solution Speed up productivity in a team Improves system and application design Carpenter: connector design pattern
  23. 23. Object-oriented Design Patterns Creational  The creational patterns aim to separate a system from how its objects are created, composed, and represented  They increase the system’s flexibility in terms of the what, who, how, and when of object creation Structural  Structural patterns are concerned with how classes and objects are composed to form larger structures Behavioral  Behavioral patterns identify common communication patterns between objects  They increase flexibility in carrying out this communication
  24. 24. Creational Patterns Factory Singleton Prototype (skip) Abstract Factory (skip) Builder (skip)
  25. 25. Creational - Factory example Logging C# example available on class homepage (136 project) Polymorphism
  26. 26. Creational - Factory
  27. 27. Creational - Singleton
  28. 28. Creational - Singleton Code C# interview question
  29. 29. Structural Design Patterns Decorator Proxy Adapter Facade Bridge (skip) Composite (skip) Flyweight (skip)
  30. 30. Structural - Decorator example
  31. 31. Structural - Decorator .NET libraries are based on decorator pattern
  32. 32. Structural - Proxy example
  33. 33. Structural - Proxy
  34. 34. Structural - Adapter example
  35. 35. Structural - Adapter
  36. 36. Structural - Facade
  37. 37. Behavioral Pattern Strategy Chain of Responsibility Iterator (skip - you have seen this in C# lecture “enumerator”) Skip: Observer, Command, Mediator, Memento, Stat e, others…
  38. 38. Behavioral - Strategy example Polymorphism
  39. 39. Behavioral - Strategy Polymorphism Client may come From GUI
  40. 40. Behavioral - Chain example Polymorphism
  41. 41. Behavioral - Chain Polymorphism
  42. 42. Review question Why does domain model a better pattern at the end? What are the three categories of OO design pattern? Why are inheritance and polymorphism the center of OO design pattern?  Open/close principal, code flexibility.
  43. 43. Demo Code Business Logic Layer Domain Objects Error Logging implementation (factory pattern) Data Transfer Object
  44. 44. Your Assignment Due next Thursday Design and develop business layer based on UML  UML class diagram for Domain Object Model  C# Domain Model classes  C# Domain Business Logic  Must use creational pattern for error-logging (log to db or file based on app.config)  Must use asynchronous call for error-logging  Validations (regular expression – cover in day6) Developing test cases for your business layer
  45. 45. References .NET : Architecting Applications for the Enterprise Design Patterns: Elements of Re-usable Object-Oriented Software C# Design Patterns

×