Framework is - Tistory

108
http://www.arload.net

Transcript of Framework is - Tistory

Page 1: Framework is - Tistory

http://www.arload.net

Page 2: Framework is - Tistory

Framework is ..

Page 3: Framework is - Tistory

Framework is…

Page 4: Framework is - Tistory

Douglas C. Schmidt Says..Frameworks define “semi-complete” applicationthat embody domain-specific object structures and functionality.

Page 5: Framework is - Tistory

Class Library Component Architecture

App SpecificLogic

OO Design

EventLoop

DATABASE ADTs

MATH NETWORKING

GRAPHICS GUI

Singleton Strategy

Reactor Adapter

State Active Object

Invocations

Selections

Application Block

Design Pattern

Libraries is..

Page 6: Framework is - Tistory

DATABASE

Singleton

GRAPHICS

Adapter

EventLoop

Reactor

NETWORKING

Active Object

GUI

State

App SpecificLogic

MATH

ADTs

Callbacks

Invocations

Application FrameworkComponent Architecture

But Framework is ..

Page 7: Framework is - Tistory

Why Do You Need Framework?

Avoid Duplication Productivity

Page 8: Framework is - Tistory

Welcome to

My Framework

Journey!

Page 9: Framework is - Tistory

“Framework Engineering”, TechED 2007 Europe

“Framework Design Guidelines” , Addison Wesley

Krzysztof Cwalina

Program Manager on .NET Framework Team

Page 10: Framework is - Tistory

5 Topics..

Organization

Planning

Architecture

Design

Development

DO P A V

Page 11: Framework is - Tistory

The most powerful design tool

O

Page 12: Framework is - Tistory

Project Management Triangle

Scope

Cost Time

O

Page 13: Framework is - Tistory

Project Management Triangle

Organization

O

Page 14: Framework is - Tistory

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

O

Page 15: Framework is - Tistory

Conway's law

If you have 4 groups working on a compiler,

you’ll get a 4-pass compiler.

O

Page 16: Framework is - Tistory

Organization Structure

Software Structure

O

Page 17: Framework is - Tistory

Conway's Clean State Approach

1• Define the business mission

2• Learn the business process from business owners

3• Re-engineer these process to fit the mission

4

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

O

Page 18: Framework is - Tistory

Your Company Culture Is ..

Voluntary ??O

Page 19: Framework is - Tistory

Familial ??O

Your Company Culture Is ..

Page 20: Framework is - Tistory

Peremptory O

Page 21: Framework is - Tistory

Organizational InfluencesSize of Organization

Small Team

Simple Design

Consistency Design

Focus on 80/20 Rules

O

Page 22: Framework is - Tistory

Large Team

Organizational InfluencesSize of Organization

Powerful Design

Lack Consistency

Remove Requirements

O

Page 23: Framework is - Tistory

Organizational InfluencesOrganization’s Culture/Biases

Customer-Focused

End-2-End Scenarios

O

Page 24: Framework is - Tistory

Organizational InfluencesOrganization’s Culture/Biases

Technology-Focused

Long Lasting Architecture

O

Page 25: Framework is - Tistory

Decision Making Process is..

O

Page 26: Framework is - Tistory

Ensuring we are building the right thing

P

Page 27: Framework is - Tistory
Page 28: Framework is - Tistory

P

Page 29: Framework is - Tistory

Focus: features

Results: stability,

incremental

improvements, not

great end-to-end

scenarios

Peanut Butter

Focus: scenarios

Results: Excitement,

breakthroughs, but

beware of leaving

existing customers

behind

Skyscrapers

P

Page 30: Framework is - Tistory

Moderation (中庸)MileStone = Scenarios + Feature

Planning M1 M2

ReleaseTesting

Feature completeVision statement RTM

Technology Preview Beta 1 Beta 2 RC1

Page 31: Framework is - Tistory

Ensuring the long term health of the framework

A

Page 32: Framework is - Tistory

A

Right Way??Choose right types.

Page 33: Framework is - Tistory

Taxonomy of TypesLibraries , Primitives, Abstractions

A

Page 34: Framework is - Tistory

PrimitivesVery 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 35: Framework is - Tistory

Definition:Libraries are types that are not passed between components

ExamplesEventLog, Debug,

Easy to EvolveLeave old in, add new one

Beware of duplication!

A

Libraries

Page 36: Framework is - Tistory

Abstractions

Definition:Abstractions are interfaces or classes with unsealed members that are passed between components.

ExamplesStream, IComponent

Hard to Evolve

Unfortunately, pressure to evolve

A

Page 37: Framework is - Tistory

Primitive Oriented Design

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

Great evolvability, poor usability (sometimes)

Low level stable 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 38: Framework is - Tistory

for primitive.. C# 3.0 New Featurenamespace MyCompany.StringManipulation {

public static class StringExtensions{

public static bool IsNullOrEmpty(this string s){ return String.IsNullOrEmpty(s);

}

}

}

using MyCompany.StringManipulation;

string message= “hello world”;

if(message.IsNullOrEmpty()){

Console.WriteLine(“EMPTY”);

}

Page 39: Framework is - Tistory

Component Oriented Design

Rich APIs with lots of features, thus with lots of dependencies

Great usability, poor evolvability

Good for higher level components, not for the core of a platform

A

Page 40: Framework is - Tistory

A

DO Manage Dependencies..

Page 41: Framework is - Tistory

A

Lego, Plug ??

Component is ..

Page 42: Framework is - Tistory

A

.. a set of types that ship and evolve as a unit.

Page 43: Framework is - Tistory

A

Dependency

API

Implementation

Circular

Page 44: Framework is - Tistory

API Dependency

Component A has an API dependency on component B,

if a type in B shows in the publicly accessible API surface of a type in A.

This includes:Base types and implemented interfaces

Generic parameter constraints

Return types and parameters of members

Applied attributes

Nested types

A

Page 45: Framework is - Tistory

Implemenatin Dependency

If a type in A uses a type in B in its implementation.

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

A

Page 46: Framework is - Tistory

Circular Dependency

Component A depends on component B and

Component B depends on component A (even indirectly).

A

Page 47: Framework is - Tistory

Packaging Principle

Package Cohesion PrincipleREP (Release Reuse Equivalency)

CCP (Common Closure Principle)

CRP (Common Reuse Principle)

Package Coupling PrincipleADP (Acyclic Dependencies Principle)

SDP (Stable Dependencies Principle)

SAP (Stable Abstraction Principle)

ARobert C. Martin, Principle of Package Architecture

http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf

Page 48: Framework is - Tistory

A

Page 49: Framework is - Tistory

Solution is Layering..

A

Page 50: Framework is - Tistory

xDepend (NDepend)

NDepend - http://www.ndepend.com

Page 51: Framework is - Tistory

A

BCL

WPF XML

Reflection

Page 52: Framework is - Tistory

Circular Dependency

A

GUI

CommAnalysis

ProtocolModem

Control

Comm

Error

Database

Page 53: Framework is - Tistory

Creating a new packaging.

Page 54: Framework is - Tistory

A

GUI

CommAnalysis

ProtocolModem

Control

Comm

Error

Database

Message

Manager

Page 55: Framework is - Tistory

A

B

X

Y

Circular Dependency

Page 56: Framework is - Tistory
Page 57: Framework is - Tistory

A

B

X

Y<<interface>>

BY

Adding new interface

Page 58: Framework is - Tistory

Heavy Depedency

A

Page 59: Framework is - Tistory

A

Page 60: Framework is - Tistory

Heavy Dependencies and Testability

// your API

public class Tracer {

MessageQueue mq = new MessageQueue(…);

public void Trace(string message){

mq.Send(message);

}

}

// your customer’s program that is hard to test

Tracer tracer = new Tracer();

public void ProcessOrder(Order order){

tracer.Trace(order.Id);

}

Page 61: Framework is - Tistory

Inversion of Control

// your better API

public abstract class TraceListener {

public abstract void Trace(string message);

}

public class Tracer {

TraceListener listener;

public Tracer(TraceListener listener){

this.listener = listener;

}

public void Trace(string message){

listener.Trace(message);

}

}

Page 62: Framework is - Tistory

Dependency Injection

// your customer’s program that is easier to test

Tracer tracer = new Tracer(new FileListener());

public void ProcessOrder(Order order){

tracer.Trace(order.Id);

}

Page 63: Framework is - Tistory

// customer’s program that is even easier to test

Tracer tracer = container.Resolve<Tracer>();

public void ProcessOrder(Order order){

tracer.Trace(order.Id);

}

Check out DI Containers (a.k.a. IoC Containers): autofac, Castle Windsor, PicoContainer.NET, Spring.NET, StructureMap, Unity, nInject and others.

http://www.nInject.org

Page 64: Framework is - Tistory

DO balance advances with compatibility.

A

Page 65: Framework is - Tistory

Types of “Compatibility”

A

Cross-Version

Backward

Forward

Page 66: Framework is - Tistory

A

Cross-Redist.

Page 67: Framework is - Tistory

A

Page 68: Framework is - Tistory

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 69: Framework is - Tistory

AVOID duplication and overlap.

A

Page 70: Framework is - Tistory

A

Problem Space Show and Tell

PLoP – Capable, Productive and Satisfied Patterns for Productivity

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

Page 71: Framework is - Tistory

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 72: Framework is - Tistory

This is where quality happens

D

Page 73: Framework is - Tistory

Is using your framework correctly like…

Running across a desert?

Page 74: Framework is - Tistory

A

Page 75: Framework is - Tistory

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 76: Framework is - Tistory

Code Samples

D

Page 77: Framework is - Tistory

Read File

static void Main(string[] args)

{

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

string s = sr.ReadLine();

while (s != null)

{

s = sr.ReadLine();

Console.WriteLine(s);

}

}

D

Page 78: Framework is - Tistory

static void Main(string[] args)

{

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

{

Console.WriteLine(s);

}

}

Feedback (Read File)

D

Page 79: Framework is - Tistory

Object Model Listing

D

Page 80: Framework is - Tistory

Framework Design Studio Assembly Exploer

Project -> Add -> Assembly

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

Page 81: Framework is - Tistory

Framework Design Studio Assembly Review Comment

D

Page 82: Framework is - Tistory

Framework Design StudioCompare API Versions

D

Page 83: Framework is - Tistory

Framework Design StudioCompare API Versions

Red is removed,

Green is added,

Grey means inherited.

D

Page 84: Framework is - Tistory

Framework Design StudioExporting to Microsoft Word

Tools -> Export to Document

Page 85: Framework is - Tistory

DO treat simplicity as a feature.

D

Page 86: Framework is - Tistory

Remove Requirements

Reuse Existing Concepts or APIs

Adjust Abstraction Level

Three Example (Evolving Frameworks)

D

Page 87: Framework is - Tistory

DO measure, measure, and measure!

D

Page 88: Framework is - Tistory

Specification Document: Qualities

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 89: Framework is - Tistory

THE POWER OF SAMENESS

D

Page 90: Framework is - Tistory

When you pick up your rental car….

Push the seat all the way back

Find an NPR station

Find the exit

Read the manual??

Page 91: Framework is - Tistory

Oh, down to lock…

Page 92: Framework is - Tistory

How to use a key…

Page 93: Framework is - Tistory

Oh, you push the PRESS button…

Page 94: Framework is - Tistory

Who actually needs this data?

Page 95: Framework is - Tistory

You know how to drive your car

All cars work basically the same way

Your rental car is a car

Therefore, you can drive your rental car

That is…

Page 96: Framework is - Tistory

http://blogs.msdn.com/fxcop

Page 97: Framework is - Tistory

The bits customers get, … or not

V

Page 98: Framework is - Tistory

Branches and Integrations

Main

PU-staging

branch

Feature

branch

Feature

branch

PU-staging

branch

PU-staging

branch

V

Page 99: Framework is - Tistory

AVOID integrating unfinished features.

V

Page 100: Framework is - Tistory

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

V

Page 101: Framework is - Tistory

DO pay your debt.

V

Page 102: Framework is - Tistory

Planning M1 M2

ReleaseTesting

Feature completeVision statement RTM

Technology Preview Beta 1 Beta 2 RC1

Milestone Quality

Page 103: Framework is - Tistory

Milestone Quality (MQ)

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 104: Framework is - Tistory

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 106: Framework is - Tistory

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)

Page 107: Framework is - Tistory

Robert C. MartinPrinciples of Package Architecture (Design Principles and Design Patterns)

http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf (En) http://www.devpia.com/net2/EvaCast/Lecture/?cu=view&r=108 (Kr)

For Korean People..

Load to Architecthttp://www.arload.net

EvaCast (Online Free Lecture)http://www.evacast.net