using the decorator design pattern to address cross-cutting concerns

11

Click here to load reader

Upload: rob-hale

Post on 25-May-2015

643 views

Category:

Technology


2 download

DESCRIPTION

Presented 2013-07-15 to the VT .NET user group

TRANSCRIPT

Page 1: Using the Decorator Design Pattern to Address Cross-Cutting Concerns

Rob Hale

VT .NET User Group

July 15, 2013

Page 2: Using the Decorator Design Pattern to Address Cross-Cutting Concerns

Common functionality that spans layers and tiers. Examples are operations like:

authentication

authorization

caching

communication

exception management

validation

logging

Page 3: Using the Decorator Design Pattern to Address Cross-Cutting Concerns

Demo: TypicalExample

Page 4: Using the Decorator Design Pattern to Address Cross-Cutting Concerns

Every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.

A responsibility is a reason to change, and a class or module should have one, and only one, reason to change.

Page 5: Using the Decorator Design Pattern to Address Cross-Cutting Concerns

public void Execute()

{

Logger.Info("Starting execution");

Console.WriteLine("We're doing our job!");

Logger.Info("Done execution");

}

Two responsibilities:

Logging

Processing

Page 6: Using the Decorator Design Pattern to Address Cross-Cutting Concerns

Demo: DependencyInjection

Page 7: Using the Decorator Design Pattern to Address Cross-Cutting Concerns

The good news

Processor is more loosely coupled

The bad news

Processor still has two responsibilities

Page 8: Using the Decorator Design Pattern to Address Cross-Cutting Concerns

IComponent + Operation()

ConcreteComponent + Operation()

Decorator - iComponent + Operation()

ConcreteDecorator - iComponent + Operation()

Page 9: Using the Decorator Design Pattern to Address Cross-Cutting Concerns

Demo: DecoraterExample

Page 11: Using the Decorator Design Pattern to Address Cross-Cutting Concerns