framework engineering

77
Son YoungSu [email protected] Microsoft MVP EvaCast Leader Devpia Architecture Sysop Load to Architect (http://www.arload.net )

Upload: youngsu-son

Post on 22-Jan-2015

1.611 views

Category:

Technology


1 download

DESCRIPTION

I translate Framework Design Guideline to Korean. This Book is very impressed to me. So I want to share Krzysztof Cwalina's Knowledge. I re-edit his presentation and add my opinion.

TRANSCRIPT

Page 1: Framework Engineering

Son [email protected]

Microsoft MVPEvaCast Leader

Devpia Architecture SysopLoad to Architect (http://www.arload.net)

Page 2: Framework Engineering
Page 3: Framework Engineering

FrameworksFrameworks define define “semi“semi--complete” applicationcomplete” applicationthat embody domainthat embody domain--specific object structures and functionality.specific object structures and functionality.

Page 4: Framework Engineering

Class Library Class Library Component Component ArchitectureArchitecture

App SpecificApp SpecificLogicLogic

OO DesignOO Design

EventEventLoopLoop

DATABASEDATABASE ADTsADTs

MATHMATH NETWORKINGNETWORKING

GRAPHICSGRAPHICS GUIGUI

SingletonSingleton StrategyStrategy

ReactorReactor AdapterAdapter

StateState Active ObjectActive Object

InvocationsInvocations

SelectionsSelections

Application BlockApplication Block

Design PatternDesign PatternDATABASEDATABASE

SingletonSingleton

GRAPHICSGRAPHICS

AdapterAdapter

EventEventLoopLoop

ReactorReactor

NETWORKINGNETWORKING

Active ObjectActive Object

GUIGUI

StateState

App SpecificApp SpecificLogicLogic

MATHMATH

ADTsADTs

CallbacksCallbacks

InvocationsInvocations

Application Application FrameworkFrameworkComponent ArchitectureComponent Architecture

Page 5: Framework Engineering

Avoid Duplication Productivity

Page 6: Framework Engineering

Do you Do you wannawanna make make good framework?good framework?

Page 7: Framework Engineering
Page 8: Framework Engineering

Motivation

Organization

Architecture

Planning

Design

Development

Resources

Page 9: Framework Engineering

“Framework Engineering”, TechED 2007 Europe

“Framework Design Guidelines” , Addison Wesley

Krzysztof Cwalina

Program Manager on .NET Framework Team

Page 10: Framework Engineering

Organization

Planning

ArchitectureDesign

Development

Your APIs

D

O

P

A

V

Page 11: Framework Engineering

The most powerful design toolThe most powerful design tool

O

Page 12: Framework Engineering

Scope

Cost Time

Page 13: Framework Engineering

Scope

Cost

Time

Organization

Page 14: Framework Engineering

DODO understand how understand how organizational structure, organizational structure, culture, and decision making processesculture, and decision making processes impaimpact your product. ct your product.

O

Page 15: Framework Engineering

If you have 4 groups working on a compiler,

you’ll get a 4-pass compiler.

Page 16: Framework Engineering

If you have four groups working on a compiler,

you’ll get a 4-pass compiler.

Organization Structure

Software Structure

Page 17: Framework Engineering

1• Define the business mission• Define the business mission

2• Learn the business process from business owners• Learn the business process from business owners

3• Re-engineer these process to fit the mission• Re-engineer these process to fit the mission

4

• Structure the IT organization to support the reengineered business processes.

• Structure the IT organization to support the reengineered business processes.

Page 18: Framework Engineering

Voluntary

Page 19: Framework Engineering

Familial

Page 20: Framework Engineering

Peremptory

Page 21: Framework Engineering

Small Team

Simple Design

Consistency Design

Focus on 80/20 Rules

Page 22: Framework Engineering

Large Team

Powerful Design

Lack Consistency

Remove Requirements

Page 23: Framework Engineering

Customer-Focused

End-2-End Scenarios

Page 24: Framework Engineering

Technology-Focused

Long Lasting Architecture

Page 25: Framework Engineering

Individuals Empowered -> Time to Market

Hierarchy -> Interoperability and Integration

Consensus -> Team Building

Page 26: Framework Engineering

Ensuring we are building the right thing Ensuring we are building the right thing

P

Page 27: Framework Engineering
Page 28: Framework Engineering
Page 29: Framework Engineering

Focus: featuresFocus: features

Results: Results: stability, stability,

incremental incremental

improvements, not improvements, not

great great endend--toto--end end

scenariosscenarios

Peanut ButterPeanut Butter

Focus: scenarios Focus: scenarios

Results: Results: Excitement, Excitement,

breakthroughs, but breakthroughs, but

beware of leaving beware of leaving

existing customers existing customers

behind behind

SkyscrapersSkyscrapers

P

Page 30: Framework Engineering

Planning M1 M2

ReleaseTesting

Feature completeVision statement RTM

Technology Preview Beta 1 Beta 2 RC1

Page 31: Framework Engineering

Ensuring the long term health of the frameworkEnsuring the long term health of the framework

A

Page 32: Framework Engineering

DO manage your dependencies.

A

Page 33: Framework Engineering

A Component is a set of types that ship and evolve as a unit. Componentization is a process of organizing types into components, with explicitly designed and controlled dependencies between componexplicitly designed and controlled dependencies between componentsents. NOTE: Componentization is different from assembly factoring (i.e. an assembly might have more than one component)

A

Page 34: Framework Engineering

API Dependency: Component A has an API dependency on component B, if a type in B shows in the publicly accessible (public or protected) API surface of a type in A. This includes:

Base types and implemented interfacesGeneric parameter constraintsReturn types and parameters of membersApplied attributesNested types

Implementation Dependency: If a type in A uses a type in B in its implementation.

Hard Dependencies (required to run)Soft Dependencies (optional)

Circular Dependency occurs when component A depends on component B and component B depends on component A (even indirectly).

Note: Two (or more) components with a circular API dependencies can be considered a single component for all practical purposes.

A

Page 35: Framework Engineering

A

Layering is a process of organizing components in layers and enforcing dependency rules between components in these layers.

Page 36: Framework Engineering

Types in a component can freely depend on each other Cross-component dependencies must be carefully controlled A component can freely take dependencies on components in a lower layer A component must not have hard dependencies on components in higher layers. A component should avoid soft dependencies on components in higher layers. Dependencies between components of the same layer must be carefully managed. [NOT

E: we have an approval process for these] In general it’s good to minimize dependencies, if it does not create to much duplic

ation (bloat)

A

Page 37: Framework Engineering

NDepend - http://www.ndepend.com

Page 38: Framework Engineering
Page 39: Framework Engineering

Primitives

Abstractions

Reusable Components

Page 40: Framework Engineering

Very little policy (behavior design decisions)

Stable design

Commonly appear in publicly accessible APIs

Almost impossible to evolve/change design; any design changes have huge breaking change impact on other APIs

Example: Int32, String

A

Page 41: Framework Engineering

Interfaces, abstract classes, some concrete classes with extensive virtual surface.

Similar to Primitives (show in APIs), but usually have more policy (though less than libraries)

The hardest types to design rightWith the exception on a few historically well understood abstractions (lists, streams, etc.), abstractions with more than 2-3 members are rarely successful.

Difficult to evolve

Glue between parts of the frameworkThrough polymorphism

Very useful for decoupling components

Examples: Stream, IEnumerable<T>

A

Page 42: Framework Engineering

Perform operations on primitives and abstractions (or the system)

Almost never passed around

Change often as frameworks evolveXmlDocument (Fx 1.0 – XML DOM)

XPathDocument (Fx 2.0 - XPath)

XDocument (Fx 3.5 – Linq to XML)

Relatively easy to evolve (if designed and used properly); they can be simply replaced.

Examples: XmlDocument, EventLog, SerialPort

A

Page 43: Framework Engineering

Rich APIs with lots of features, thus with lots of dependenciesGreat usability, poor evolvabilityE.g. Object.GetType() – Every object has very easy access to its type, but also every object depends on ReflectionGood for higher level components, not for the core of a platformNOTE: “Component” is an overloaded term. In this context it does not have anything to do with “componentization.” Unfortunately, COD is already an established term.

A

Page 44: Framework Engineering

A.K.A. “Handle based design” (functional)

Great evolvability, poor usability (sometimes)

Low level sable primitives + high level reusable components with limited dependencies other than to the primitives

E.g. Type.GetType(object) – works, but not as convenient as Object.GetType

A

Page 45: Framework Engineering

Members with “heavy” dependencies can be extension methods for primitives in a separate component.

This is essentially functional programming// low level assembly with no dependency on globalizationnamespace System {

public struct Decimal {public string ToString(); // culture independent

}}

// higher level assemblynamespace System {

public static class DecimalFormatter {// decimal point character is culture sensitive public static string ToString(this Decimal d, string format);

} }

Note: Same namespace makes the API easy to use A

Page 46: Framework Engineering

DO balance advances with compatibility.

A

Page 47: Framework Engineering

Cross-Version Compatibility: code written for a version of a redist works on a different version of the same redist.Cross-Redist Compatibility: code written for a redist works on a different redist.Backward Compatibility: code written for a version of a redist works on a newer version of the same redist.Forward Compatibility: code written for a version of a redist works on a previous version of the same redist.

A

Page 48: Framework Engineering

Binary Compatibility: a binary runs on a different version or a different redist than what it was build for without recompilation.

Source Compatibility: source code compiling on a version of a redist can be recompiled without changes on a different version or a different redist.

API Compatibility: Stronger than source. Weaker than binary. Source compatibility allows for some changes in APIs (e.g. covariant changes to input parameters). API Compatibility does not.

A

Page 49: Framework Engineering

Define what’s a “breaking change”

This definition depends on the objectiveE.g. Enable portable code between Silverlight and .NET Framework

E.g. Enable cross-version portability?

For example, Silverlight interfaces cannot have less members than .NET interfaces, but concrete types can.

A

Page 50: Framework Engineering

AVOID duplication and overlap.

A

Page 51: Framework Engineering

AVOID duplication and overlap.

A

Problem Space Show and Tell

PLoP – Capable, Productive and Satisfied Patterns for Productivity

http://hillside.net/plop/plop98/final_submissions/P54.pdf

Page 52: Framework Engineering

When the new technology is “10x better”

Make sure you understand the impact on the ecosystem

What would happen if the BCL team added a new String?

What’s the migration path for code using the old API?

A

Page 53: Framework Engineering

This is where quality happensThis is where quality happens

D

Page 54: Framework Engineering

DO design APIs by first writing code samples for the main scenarios and then defining the object model to support the code samples.

D

Page 55: Framework Engineering

D

Page 56: Framework Engineering

static void Main(string[] args)

{

StreamReader sr = File.OpenText("MyFile.txt");

string s = sr.ReadLine();

while (s != null)

{

s = sr.ReadLine();

Console.WriteLine(s);

}

}

Page 57: Framework Engineering

static void Main(string[] args)

{

foreach (string s in File.ReadAllLines("MyFiles.text"))

{

Console.WriteLine(s);

}

}

Page 58: Framework Engineering

D

Page 59: Framework Engineering

Project -> Add -> Assembly

Download here - http://code.msdn.microsoft.com/fds

Page 60: Framework Engineering
Page 61: Framework Engineering
Page 62: Framework Engineering

Red is removed,

Green is added,

Grey means inherited.

Page 63: Framework Engineering

Tools -> Export to Document

Page 64: Framework Engineering

DO treat simplicity as a feature.

D

Page 65: Framework Engineering

Remove Requirements

Reuse Existing Concepts or APIs

Adjust Abstraction Level

Evolving Framework (Three Example)

D

Page 66: Framework Engineering

DO measure, measure, and measure!

D

Page 67: Framework Engineering

Performance GoalsBaseline: What do is the best my API could do?

Measure delta from the baseline

Threat ModelsThreat: What is the worst that my component could do?

Mitigate the threats

Same for many other qualities you want your framework to have

D

Page 68: Framework Engineering

The bits customers get, … or notThe bits customers get, … or not

V

Page 69: Framework Engineering

Main

PU-staging

branch

Feature

branch

Feature

branch

PU-staging

branch

PU-staging

branch

V

Page 70: Framework Engineering

AVOID integrating unfinished features.

V

Page 71: Framework Engineering

Functional SpecificationDeveloper Design SpecificationTest PlanThreat ModelAPI reviewArchitectural ReviewDependency ManagementStatic AnalysisCode CoverageTesting (Unit and Integration Tests)0 BugsPerformance

V

Page 72: Framework Engineering

DO pay your debt.

V

Page 73: Framework Engineering

Planning M1 M2

ReleaseTesting

Feature completeVision statement RTM

Technology Preview Beta 1 Beta 2 RC1

Milestone Quality

Page 74: Framework Engineering

Initiatives that are hard to do in regular milestones

Large productivity and efficiency improvements

Infrastructure changes

For example, a new source control system

Refactoring of fragile subsystems

Internal implementation documentation

Bugs backlog

V

Page 75: Framework Engineering

DO understand how organizational structure, culture, and decision making processes impact your product.

AVOID peanut-butter in Scenario Based Application.

DO manage your dependencies.

DO balance advances with compatibility.

AVOID duplication and overlap.

DO design APIs by first writing code samples for the main scenarios and then defining the object model to support the code samples.

DO treat simplicity as a feature.

DO measure, measure, and measure!

AVOID integrating unfinished features.

DO pay your debt.

Page 76: Framework Engineering

Framework Design Guidelines:Conventions, Idioms, and Patterns for Reusable .NET LibrariesKrzysztof Cwalina, Brad Abrams

http://www.gotdotnet.com/team/fxcop

Page 77: Framework Engineering

Douglas C. Schmidt (PLoP Editor, POSA 2, 4 Writter)

JAWS: An Application Framework for High Performance Web Systemhttp://citeseer.ist.psu.edu/81775.html (En)http://www.devpia.com/net2/EvaCast/Lecture/?cu=view&r=11 (Kr)

Ralph Johnson (GoF , Design Patterns)

Evolving Frameworkshttp://st-www.cs.uiuc.edu/users/droberts/evolve.html (En)http://arload.wordpress.com/2008/09/15/evolvingframeworks/ (Kr)