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

c design patterns proxy
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

@ardalis | ardalis.com | weeklydevtips.com

FORCE MULTIPLIER FOR DEV TEAMS

Steve Smith

APPLYING THE PROXY PATTERN

C# Design Patterns: Proxy

slide-2
SLIDE 2

t h s

What problems does proxy solve? How is the proxy pattern structured? Apply the pattern in real code Recognize related patterns

Objectives

slide-3
SLIDE 3

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

slide-4
SLIDE 4

Real World Examples

slide-5
SLIDE 5

Common Software Examples

slide-6
SLIDE 6

Common Software Examples

User Interface Twittergrambook ServiceProxy Client App API Service Twittergrambook API Endpoints

slide-7
SLIDE 7

Proxy Usage in Software

slide-8
SLIDE 8

Proxy Structure

slide-9
SLIDE 9

Proxy Structure

slide-10
SLIDE 10

Virtual Proxy

Proxy Variants

Remote Proxy Smart Proxy Protective Proxy

slide-11
SLIDE 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

slide-12
SLIDE 12

Demo

t h s

Virtual Proxy in C#

slide-13
SLIDE 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

slide-14
SLIDE 14

Demo

t h s

Remote Proxy in C#

slide-15
SLIDE 15

s h s

Smart Proxy Performs additional logic around resource access Resource counting Cache management Locking shared resources

slide-16
SLIDE 16

Demo

t h s

Smart Proxy in C#

slide-17
SLIDE 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

slide-18
SLIDE 18

Demo

t h s

Protective Proxy in C#

slide-19
SLIDE 19

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

slide-20
SLIDE 20

Separation of Concerns

Related Principles

Avoid mixing separate concerns or ideas in the same class or method

Loose Coupling

Prefer loose coupling to third party dependencies

Single Responsibility

Classes should have only

  • ne responsibility; one

reason to change

Some principles suggest the use of a Proxy as the solution in certain cases.

1

slide-21
SLIDE 21

Flyweight Adapter Prototype Decorator

Related Patterns

slide-22
SLIDE 22

t h s

A proxy controls access to another class There are at least 4 kinds of proxy variants: Virtual 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

Key Takeaways

slide-23
SLIDE 23

@ardalis | ardalis.com | weeklydevtips.com

FORCE MULTIPLIER FOR DEV TEAMS

Steve Smith

APPLYING THE PROXY PATTERN

C# Design Patterns: Proxy