32

Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data
Page 2: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Don Smith, Program ManagerMicrosoft patterns & practices

Page 3: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Agenda

The data access layer and your options

Patterns for keeping entities consistent

Patterns for managing entity differences

Data access technology assessment

Other data access challenges

Summary and questions

Page 4: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Layers & Relationships

ConsiderationsDomain complexity

Developer experience

Greenfield vs. brownfield

Desired approach: data, code, or model first?

Object/schema fidelity

Two OptionsKeep entities consistent

Manage their differences

Data Access Layer DataStorage

BusinessLogic Layer

BusinessLogicLayer

Data Storage

Page 5: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Keeping Entities Consistent

Recommended when domain is less complex

Restricts object-oriented design options

Can benefit from code generation strategies

More difficult to evolve over time, but easier to manage

Common patternsRow Data Gateway

Table Data Gateway

Table Module

Active Record

Record Set

We have choicesShape of the objects

How to combinedata and logic

Page 6: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Pre-Built Types

Record Set (DataSet)Contains the data as rows and columns

Table Data GatewayEncapsulates all SQL

Can return record sets

Table ModuleAccepts a record set

Contains business logic

when objects and schema have a simple relationship

RowsColumns

RecordSet

Find() : RecordSetUpdate(a, b, c)Insert(a, b, c)Delete(id)

TableDataGateway

Process(RecordSet)Calculate(RecordSet)

TableModule

Page 7: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Custom Types

Row Data GatewayRepresents a table’s rowIncludes all CRUD capability

Transaction ScriptContains business logic

Active RecordRepresents a table’s rowContains business logicIncludes all CRUD capability

ID : longFirstName : stringLastName : stringUpdate(first, last)Insert(first, last)Delete(id)

RowDataGateway

ID : longFirstName : stringLastName : stringUpdate(first, last)Insert(first, last)Delete(id)Process()

ActiveRecord

ProcessCostChange()CalculateAdjustment()

TransactionScript

when objects and schema have a simple relationship

Page 8: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Managing Entity Differences

Appropriate for complex domain logic

Requires more developer experience

Can leverage more OO (GoF) design patterns

Appropriate for apps that evolve over time

Common patternsDomain Model

Data Mapper

Repository

Unit of Work

Specification

Page 9: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Storefront Overview

SQLServer

ASP.NETMVC

DataServices

Customer Retailer

Broker

• Manages product information

• Maintains inventory

• Processes and ships orders

IE WPF

Silverlight

• Collects a percentage from each sale• Views sales & site usage reports

• Searches for products

• Buys products• Views order

status• Rates products

and retailers

Page 10: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Storefront Reference Implementation

Page 11: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Domain Model & Mapping

Domain ModelAn object model that represents the domain

Contains the combination of data and business logic

Two basic optionsMay be robust and leverage OO principles

May be straightforward in less complex scenarios

May have no knowledge of data access technology

Data MapperRepresents an association of types and properties across the domain model and data model

Almost always aware of the data access technology

Implementations are often included in O/RM solutions

Mapping support varies

Page 12: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Repository

Collection-type interface to data access

Mediates between domain model and mapper

Implementations are specific to a technology

GetById(id)GetAll()Add(object)Update(object)Delete(id)

Repository

Page 13: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Unit of Work

Maintains a list of new, changed and deleted objects and coordinates persisting changes

Can be used across multiple repositories

SubmitChanges()CancelChanges()

UnitOfWork

Page 14: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Specification/Query Object

An object that represents the criteria of a query

Allows queries to be easier to manage

Avoids the need for a method for each query

Field : stringValue : objectOperator : OpEnum

Specification

Page 15: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Technology Assessment

ADO.NETDataSet

DataAdapter

DataReader

LINQ to SQLO/RM for simple mappings

ADO.NET Entity FrameworkO/RM for more complex mappings

Page 16: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Related Challenges

Domain Model ResponsibilitiesSerialization (DTOs)

Data binding

Edit tracking

Validation

Domain Model RepresentationsSubset of the type

View models

Page 17: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Summary

Steps for making choices1. Determine consistency possibilities between the

domain model and the data modelKeep entities consistent

Manage their differences

2. Choose shape of the typesPre-built

Custom built

3. Determine how to attach the business logicInfluenced by the shape of the types

Page 18: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Resources

Don’s email: [email protected]

Project’s community site: http://dataguidance.codeplex.com

Patterns of Enterprise Application Architecturehttp://www.martinfowler.com/eaaCatalog

The Microsoft Patterns & Practices Teamhttp://microsoft.com/practices

Page 20: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS,

IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 22: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Announcement Title

Page 23: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

PowerPoint TemplateSubtitle color

Set the slide title in “title case” and subheads in “sentence case”

The subhead color is defined for this template as the fourth font color from the left

Font Size RequirementsMain bullet points must not be smaller than 24pt

Do NOT use any font size lower than 20pt

Set subhead to 36pt or smaller so it will fit on a single line

Turn off Auto Resizing on all text boxes

Page 24: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

PowerPoint Guidelines

Font, size, and color for text have been formatted for you in the Slide Master

Use the color palette shown below

See next slide for additional guidelines

Hyperlink color: www.microsoft.com

Sample Fill

Sample Fill

Sample Fill

Sample Fill

Sample Fill

Sample

Fill

Sample

Fill

Sample

Fill

Sample

Fill

Sample

Fill

Page 25: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Use white text only on these colors

Instructions on Color Readability

Colors are brighter when projected, so contrast and readability are diminished

Sample SampleSample

Sample

Sample

Sample SampleSample

Sample Sample

Use black or dark gray text only on these colors

Page 26: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Slide for Showing Software Code

Use this layout to show software codeThe font is Consolas, a monospace fontThe slide doesn’t use bullets but levels can be indented using the “Increase List Level” icon on the Home menuTo use straight quotes " instead of smart quotes ”, do this:1.Click on the Office Button in the upper left corner2.At the bottom of the menu, choose PowerPoint Options3.From the left pane, select Proofing4.Click on the AutoCorrect Options button5.Select the AutoFormat As You Type tab, and deselect “Straight quotes” with “smart quotes”. Then Click OK.

Page 27: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Table Format

Table TitleColumn 1 Column 2 Column 3 Column 4 Column 5

Page 28: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Bar Chart Example

4.3

2.5

3.5

4.5

2.4

4.4

1.8

2.8

2 2

3

5

Category 1 Category 2 Category 3 Category 4

Chart Title

Series 1 Series 2 Series 3

Page 29: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Pie Chart Example

58%23%

10%9%

Chart Title

1st Qtr

Page 30: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data
Page 31: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Related Content

Breakout Sessions (session codes and titles)

Interactive Theater Sessions (session codes and titles)

Hands-on Labs (session codes and titles)

Hands-on Labs (session codes and titles)

Page 32: Don Smith, Program Manager Microsoft patterns & practicesdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670... · 2018-10-16 · Common patterns Row Data Gateway Table Data

Track Resources

Resource 1

Resource 2

Resource 3

Resource 4