c design patterns proxy
play

C# Design Patterns: Proxy APPLYING THE PROXY PATTERN Steve Smith - PowerPoint PPT Presentation

C# Design Patterns: Proxy APPLYING THE PROXY PATTERN Steve Smith FORCE MULTIPLIER FOR DEV TEAMS @ardalis | ardalis.com | weeklydevtips.com t h s What problems does proxy solve? Objectives How is the proxy pattern structured? Apply the


  1. C# Design Patterns: Proxy APPLYING THE PROXY PATTERN Steve Smith FORCE MULTIPLIER FOR DEV TEAMS @ardalis | ardalis.com | weeklydevtips.com

  2. t h s What problems does proxy solve? Objectives How is the proxy pattern structured? Apply the pattern in real code Recognize related patterns

  3. Problem: Need to control access to a type for performance, security, or other reasons.

  4. Real World Examples

  5. Common Software Examples

  6. Common Software Examples API Service Client App User Interface Twittergrambook Twittergrambook API ServiceProxy Endpoints

  7. Proxy Usage in Software

  8. Proxy Structure

  9. Proxy Structure

  10. Proxy Variants Virtual Proxy Remote Proxy Smart Proxy Protective Proxy

  11. s h s Virtual Proxy Stands in for an expensive-to-create object Typically responsible for getting real object UI Placeholders Lazy-Loaded Entity Properties

  12. t h s Demo Virtual Proxy in C#

  13. s h s Remote Proxy Client works with proxy as if remote resource were local Hides network details from client Centralizes knowledge of network details

  14. t h s Demo Remote Proxy in C#

  15. s h s Smart Proxy Performs additional logic around resource access Resource counting Cache management Locking shared resources

  16. t h s Demo Smart Proxy in C#

  17. s h s Protective Proxy Manages access to a resource based on authorization rules Eliminates repetitive security checks from client code and the resource itself Acts as a gatekeeper around a resource

  18. t h s Demo Protective Proxy in C#

  19. When used properly, proxy implementations help you to follow Separation of Concerns and the Single Responsibility Principle.

  20. Related Principles Some principles suggest the use of a Proxy as the solution in certain cases. 1 Separation of Concerns Loose Coupling Single Responsibility Avoid mixing separate Prefer loose coupling to Classes should have only concerns or ideas in the third party dependencies one responsibility; one same class or method reason to change

  21. Related Patterns Decorator Prototype Adapter Flyweight

  22. t A proxy controls access to another class h s There are at least 4 kinds of proxy variants: Key Virtual Takeaways Remote Smart Protective Proxy classes can be generated automatically, especially remote proxies An appropriate use of proxy often helps your code follow good coding principles Latest sample code: https://github.com/ardalis/DesignPatternsInCSharp

  23. C# Design Patterns: Proxy APPLYING THE PROXY PATTERN Steve Smith FORCE MULTIPLIER FOR DEV TEAMS @ardalis | ardalis.com | weeklydevtips.com

Recommend


More recommend