SlideShare a Scribd company logo
10 Years of Framework Design Guidelines 	Brad Abrams 	Product Unit Manager 	Microsoft Corporationhttp://blogs.msdn.com/brada 	Twitter: @brada
Happy 10 Year Birthday
Happy 10 Year Birthday JoyeuxAnniversaire
Happy 10 Year Birthday Proficiat met je verjaardag
Member Design
10 years ago….
Communicate via leaving artifacts  Framework Design Artifacts: ,[object Object]
 Methods
 Events
 Constructors,[object Object]
Properties public class ArrayList { public int Count {get;}} Property getters should be simple and therefore unlikely to throw exceptions Properties should not have dependencies on each other Setting one property should not affect other properties Properties should be settable in any order
Properties versus Methods Use a Property: If the member logical attribute of the type Use a method:  If the operation is a conversion,such as ToString() If the getter has an observableside effect If order of execution is important If the method might not return immediately If the member returns an array
Properties and returning arrays public Employee[] All {get{}} public Employee[] GetAll() {} Calling Code EmployeeList l = FillList(); for (int i = 0; i < l.Length; i++){    if (l.All[i] == x){...} }  if (l.GetAll()[i]== x) {...} Moral: Use method if the operation is expensive
Today…
Extension Methods namespace 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”); }
Extension methods marry the usability offered by object-oriented APIs with the flexibility of functional APIs.
CONSIDER using extension methods to "add" methods to interfaces public interface IFoo{     void Bar(string x, bool y);     void Bar(string x); } public static class IFooExtensions{     public static void Bar(this IFoo foo, string x){         foo.Bar(x,false);     } }  … IFoo foo = …; foo.Bar(“Hi!”);
CONSIDER using extension methods to manage dependencies Uri uri = “ftp://some.ftp.uri”.ToUri();  // higher level assembly (not mscorlib)  namespace System.Net {     public static class StringExtensions{         public static Uri ToUri(this string s){ … }      }  }
AVOID frivolously defining extension methods, especially on types you don’t own  Might add clutter Choose namespaces for sponsor types carefully Remember that not all languages support extension methods Users will have to use static method call syntax
AVOID defining extension methods on System.Object // C# declaration of the extension method public static class SomeExtensions{     static void SomeMethod(this object o){…} }   ‘ VB will try to find the method at runtime ‘ … but extension methods are resolved at ‘ compile time. Dim o As Object = … o.SomeMethod() ‘ THIS WILL THROW ‘ VB users will have to call the method using the regular static method call syntax. SomeExtensions.SomeMethod(o)
Type Design
10 years ago….
Framework Design Theater  The Main Character: Bright young developer The Setting: Her first big project The Setup: Create a class that models a car Actions required: Start and Drive
Design Pass One: Meets Requirements    Pass one: meets requirements
Design Pass Two: More than Enough
Design Pass Three: Way too much 25
Time to Ship… Time to cut…
What we ship: Too much and not enough… 27
V.Next: Worse Yet Now we want to add Color and Model, and we know exactly how But it is much harder because the design is half done and mostly wrong
The moral Do as little as possible now (but no less) to ensure room for extensibility in the future
Abstract and Base classes Prefer broad, shallow hierarchies Less than or equal to 2 additional levels – Rough rule! Contracts and responsibilities are difficult to maintain and explain in deep complex hierarchies Consider making base classes not constructible (that is, use abstract classes) Make it clear what the class is for Provide a protected constructor for subclasses to call System.Exception should not have had a public constructor
Virtual Method Example public class TheBase : Object {    public override string ToString() {       return “Hello from the Base";    } } public class Derived : TheBase {    public override string ToString() {       return “Hello from Derived";    } }
Virtual Methods What is printed out? Derived d = new Derived();Console.WriteLine (d.ToString()); TheBase tb = d;Console.WriteLine (tb.ToString()); Object o = tb;Console.WriteLine (o.ToString());
Virtual Methods They all output “Hello from Derived”. Why? Method call virtualizes at runtime The static type doesn’t matter This is the danger and power of virtual methods Danger: Owner of base classes cannot control what subclasses do Power: Base class does not have to change as new subclasses are created
Overriding: Follow the Contract Don’t change the semantics of member Follow the contract defined on the base class All Virtual members should define a contract Don’t require clients to have knowledge of your overriding Should you call the base?
Virtual and non-virtual Use non-virtual members unless you have specifically designed for specialization Have a concrete scenario in mind Write the code! Follow the Liskov Substitution Principle References to base types must work with derived types without knowing the difference  Must continue to call in the sameorder and frequency Cannot increase or decrease range of inputs or output Barbara Liskov
Interface Usage public interface IComparable {    int CompareTo(object obj);} No common implementation (the ActiveX problem) Challenging to version over releases The smaller, more focused the interface the better 1-2 members are best But interfaces can be defined in terms of other simpler interfaces
	The great proof of madness is the disproportion of one's designs to one's means.Napoleon Bonaparte
Today…
Type Dependency Management Careful dependency management is the necessary ingredient to successful evolution of frameworks. Without it, frameworks quickly deteriorate and are forced out of relevance prematurely.
Framework Layering
DO NOThave upward dependencies  Avoidhorizontal dependencies WPF XML    BCL Reflection
Libraries , Primitives, Abstractions
CONSIDER placing library types higher on the dependency stack  Definition: Library types are types that are not passed between components Examples EventLog, Debug,  Easy to Evolve Leave old in, add new one Beware of duplication!
DOkeep primitives policy free (i.e. simple) Definition: Primitive types are types that are passed between components and have very restricted extensibility (i.e. no subtype can override any members) Examples Int32, String, Uri. Hard to Evolve Little need to Evolve Typically in lower layers
DO NOTcreate abstractions unless you know what you are doing Definition: Abstractions are interfaces or classes with unsealed members that are passed between components. Examples Stream, IComponent Hard to Evolve Unfortunately, pressure to evolve
Trends
10 years ago….
The Secret of Achiving Great Productivty  A Pit!!
The Pit of Success: in stark contrast to a summit, a peak, or a journey across a desert to find victory through many trials and surprises, we want our customers to simply fall into winning practices by using our platform and frameworks.  To the extent that we make it easy to get into trouble we fail.- Rico Mariani
Is using your framework correctly like… Climbing a mountain? 50
Is using your framework correctly like… Scaling a peak? 51
Is using your framework correctly like… Running across a desert? 52
Is using your framework correctly like… Falling into a pit?
Make using your framework as easy as falling into a pit – then you have achived great productivity
Today…
Test Driven Development Write tests first, design later Requires reusable APIs to be testable: ,[object Object]
Consider designing for dependency injection. ,[object Object]
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); 	} }
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); 	… }
Dependency Injection Containers // customer’s program that is even easier to test Tracer tracer = container.Resolve<Tracer>(); public void ProcessOrder(Order order){ 	tracer.Trace(order.Id); 	… } Check outDI Containers (a.k.a. IoC Containers):autofac, Castle Windsor, PicoContainer.NET, Spring.NET, StructureMap, Unity, and others.
Tools
10 years ago….
 Read the manual?? When you pick up your rental car…. Push the seat all the way back Find an NPR station Find the exit
Oh, down to lock…
How to use a key…
Oh, you push the PRESS button…
Who actually needs this data?
Why you don’t read rental car manuals ??? 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… The Power of Sameness
Naming Conventions PascalCasing – Each word starts with an uppercase letter camelCasing – First word lower case, others uppercase SCREAMING_CAPS – All upper case with underscores
Naming Conventions All types and publicly exposed members are PascalCased Parameters are camelCased public class MemberDoc {    public int CompareTo(object value)     public string Name { get;} }
Hungarian Notation Do not use Hungarian notation in publicly exposed APIs and parameter names public class CMyClass {   int CompareTo (object objValue) {..}   string lpstrName {get;}   int iValue {get;} }
On Abbreviations, acronym, initialism and the like… Avoid them!   They are a classic JLT (jargon loaded term) OK to use them once they become words Html, Xaml, etc Don’t just spell them out Use a meaningful name Abbreviations of more than 2 letters are cased as words, otherwise ALLUPPER IO vs. Html
While we are on naming… Good naming is hard—it takes time Be meaningful but brief Use US-English Colour vs. Color Principle of least surprise  Look for prior-art NumberOfElements vs. Count
FxCop – Keeping the "power of sameness" http://blogs.msdn.com/fxcop
Today…
Framework Design Studio http://code.msdn.microsoft.com/fds
Dependency Management Tools http://code.msdn.microsoft.com/fxarch Define Components <Group ID=“Component1”> 		<Bin Name=“MyCompany.FeatureA.dll”/> 		<Bin Name=“MyCompany.FeatureB.dll”/> 	</Group> Define Rules  		<Allow From=“Component1" To=“WPF"/> 		<Deny To=“XMLDOM”> Run and Get Output: From group Component1:    MyCompany.FeatureA.dll should not depend on: 	SomeOtherComponent 	   SomeOtherComponent.dll Also check out NDepend – a tool for visualizing dependencies.
Summary  10 years of Framework design.. Core Principles of Framework design have stayed the same There are some significant new advances Check out the new book! Brad Abrams http://blogs.msdn.com/brada Twitter: @brada
Q&A
© 2008 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.

More Related Content

What's hot

"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design PrinciplesSerhiy Oplakanets
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examples
agni_agbc
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
Intro C# Book
 
Abstraction
AbstractionAbstraction
Abstraction
adil raja
 
Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Object Oriented Programming : Part 2
Object Oriented Programming : Part 2
Madhavan Malolan
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
Oum Saokosal
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
mohamedsamyali
 
On Coding Guidelines
On Coding GuidelinesOn Coding Guidelines
On Coding Guidelines
DIlawar Singh
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
Bozhidar Bozhanov
 
Scala the good and bad parts
Scala the good and bad partsScala the good and bad parts
Scala the good and bad partsbenewu
 
Typescript
TypescriptTypescript
Typescript
Nikhil Thomas
 
Object oriented programming With C#
Object oriented programming With C#Object oriented programming With C#
Object oriented programming With C#
Youssef Mohammed Abohaty
 
Oops in java
Oops in javaOops in java
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 

What's hot (16)

"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles"SOLID" Object Oriented Design Principles
"SOLID" Object Oriented Design Principles
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examples
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
Abstraction
AbstractionAbstraction
Abstraction
 
Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Object Oriented Programming : Part 2
Object Oriented Programming : Part 2
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
 
On Coding Guidelines
On Coding GuidelinesOn Coding Guidelines
On Coding Guidelines
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
Scala the good and bad parts
Scala the good and bad partsScala the good and bad parts
Scala the good and bad parts
 
Typescript
TypescriptTypescript
Typescript
 
Object oriented programming With C#
Object oriented programming With C#Object oriented programming With C#
Object oriented programming With C#
 
Oops in java
Oops in javaOops in java
Oops in java
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 

Viewers also liked

Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
Jignesh Aakoliya
 
Process Design on Prabandhan Framework
Process Design on Prabandhan FrameworkProcess Design on Prabandhan Framework
Process Design on Prabandhan Framework
Anil Mande
 
Nimble framework
Nimble frameworkNimble framework
Nimble framework
tusjain
 
Domain Driven Design Framework
Domain Driven Design FrameworkDomain Driven Design Framework
Domain Driven Design Framework
Bien Hoang
 
Framework for the analysis and design of encryption strategies based on d...
Framework for the analysis and design of encryption strategies     based on d...Framework for the analysis and design of encryption strategies     based on d...
Framework for the analysis and design of encryption strategies based on d...darg0001
 
E learning analysis and design framework
E learning analysis and design frameworkE learning analysis and design framework
E learning analysis and design framework
Eric Kluijfhout
 
OSVR Software Framework - Core - April 2015
OSVR Software Framework - Core - April 2015OSVR Software Framework - Core - April 2015
OSVR Software Framework - Core - April 2015
Ryan A. Pavlik
 
Software Engineering - 02. Framework
Software Engineering - 02. FrameworkSoftware Engineering - 02. Framework
Software Engineering - 02. Framework
Arry Arman
 
Design Frameworks for Analysis and Synthesis of Complex Systems
Design Frameworks for Analysis and Synthesis of Complex SystemsDesign Frameworks for Analysis and Synthesis of Complex Systems
Design Frameworks for Analysis and Synthesis of Complex Systems
drjanroodt
 
Software Frameworks for Music Information Retrieval
Software Frameworks for Music Information RetrievalSoftware Frameworks for Music Information Retrieval
Software Frameworks for Music Information Retrieval
Xavier Amatriain
 
Teaching requirements analysis REET 2014 at RE2014
Teaching requirements analysis REET 2014 at RE2014Teaching requirements analysis REET 2014 at RE2014
Teaching requirements analysis REET 2014 at RE2014
Luisa Mich
 
How UI Framework improves design process
How UI Framework improves design processHow UI Framework improves design process
How UI Framework improves design process
Marian Mota
 
ADUF - Adaptable Design Up Front
ADUF -  Adaptable Design Up FrontADUF -  Adaptable Design Up Front
ADUF - Adaptable Design Up Front
Hayim Makabee
 
A modern approach to game analysis and design: the AGE framework
A modern approach to game analysis and design: the AGE frameworkA modern approach to game analysis and design: the AGE framework
A modern approach to game analysis and design: the AGE framework
Roberto Dillon
 
Using Environment as a Framework for Urban Design
Using Environment as a Framework for Urban DesignUsing Environment as a Framework for Urban Design
Using Environment as a Framework for Urban Design
Rutgers University
 
How UI Framework improves design process - 2015 (Dribbble meetup)
How UI Framework improves design process - 2015  (Dribbble meetup)How UI Framework improves design process - 2015  (Dribbble meetup)
How UI Framework improves design process - 2015 (Dribbble meetup)
Marian Mota
 
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
shailesh.bohra
 
Frameworks Are The Future of Design
Frameworks  Are The Future of DesignFrameworks  Are The Future of Design
Frameworks Are The Future of Design
Joe Lamantia
 

Viewers also liked (20)

Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
 
Process Design on Prabandhan Framework
Process Design on Prabandhan FrameworkProcess Design on Prabandhan Framework
Process Design on Prabandhan Framework
 
Nimble framework
Nimble frameworkNimble framework
Nimble framework
 
Domain Driven Design Framework
Domain Driven Design FrameworkDomain Driven Design Framework
Domain Driven Design Framework
 
DRE REPORT- 2014 (1)
DRE REPORT- 2014 (1)DRE REPORT- 2014 (1)
DRE REPORT- 2014 (1)
 
Framework for the analysis and design of encryption strategies based on d...
Framework for the analysis and design of encryption strategies     based on d...Framework for the analysis and design of encryption strategies     based on d...
Framework for the analysis and design of encryption strategies based on d...
 
E learning analysis and design framework
E learning analysis and design frameworkE learning analysis and design framework
E learning analysis and design framework
 
OSVR Software Framework - Core - April 2015
OSVR Software Framework - Core - April 2015OSVR Software Framework - Core - April 2015
OSVR Software Framework - Core - April 2015
 
Software Engineering - 02. Framework
Software Engineering - 02. FrameworkSoftware Engineering - 02. Framework
Software Engineering - 02. Framework
 
Design Frameworks for Analysis and Synthesis of Complex Systems
Design Frameworks for Analysis and Synthesis of Complex SystemsDesign Frameworks for Analysis and Synthesis of Complex Systems
Design Frameworks for Analysis and Synthesis of Complex Systems
 
Software Frameworks for Music Information Retrieval
Software Frameworks for Music Information RetrievalSoftware Frameworks for Music Information Retrieval
Software Frameworks for Music Information Retrieval
 
Teaching requirements analysis REET 2014 at RE2014
Teaching requirements analysis REET 2014 at RE2014Teaching requirements analysis REET 2014 at RE2014
Teaching requirements analysis REET 2014 at RE2014
 
How UI Framework improves design process
How UI Framework improves design processHow UI Framework improves design process
How UI Framework improves design process
 
ADUF - Adaptable Design Up Front
ADUF -  Adaptable Design Up FrontADUF -  Adaptable Design Up Front
ADUF - Adaptable Design Up Front
 
A modern approach to game analysis and design: the AGE framework
A modern approach to game analysis and design: the AGE frameworkA modern approach to game analysis and design: the AGE framework
A modern approach to game analysis and design: the AGE framework
 
Using Environment as a Framework for Urban Design
Using Environment as a Framework for Urban DesignUsing Environment as a Framework for Urban Design
Using Environment as a Framework for Urban Design
 
How UI Framework improves design process - 2015 (Dribbble meetup)
How UI Framework improves design process - 2015  (Dribbble meetup)How UI Framework improves design process - 2015  (Dribbble meetup)
How UI Framework improves design process - 2015 (Dribbble meetup)
 
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
 
Frameworks Are The Future of Design
Frameworks  Are The Future of DesignFrameworks  Are The Future of Design
Frameworks Are The Future of Design
 
Design engineering
Design engineeringDesign engineering
Design engineering
 

Similar to Framework Design Guidelines For Brussels Users Group

Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
YoungSu Son
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
yazad dumasia
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Steven Smith
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
Attila Bertók
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
Naresh Jain
 
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your Code
RookieOne
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
dn
 
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Featurestechfreak
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
Ólafur Andri Ragnarsson
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
Oliver Gierke
 
C# interview
C# interviewC# interview
C# interview
ajeesharakkal
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
CLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementCLR Exception Handing And Memory Management
CLR Exception Handing And Memory Management
Shiny Zhu
 
chapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptchapter 5 Objectdesign.ppt
chapter 5 Objectdesign.ppt
TemesgenAzezew
 

Similar to Framework Design Guidelines For Brussels Users Group (20)

Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your Code
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
 
C# interview
C# interviewC# interview
C# interview
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
CLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementCLR Exception Handing And Memory Management
CLR Exception Handing And Memory Management
 
Bp301
Bp301Bp301
Bp301
 
chapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptchapter 5 Objectdesign.ppt
chapter 5 Objectdesign.ppt
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
 

Recently uploaded

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 

Recently uploaded (20)

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 

Framework Design Guidelines For Brussels Users Group

  • 1. 10 Years of Framework Design Guidelines  Brad Abrams Product Unit Manager Microsoft Corporationhttp://blogs.msdn.com/brada Twitter: @brada
  • 2.
  • 3. Happy 10 Year Birthday
  • 4. Happy 10 Year Birthday JoyeuxAnniversaire
  • 5. Happy 10 Year Birthday Proficiat met je verjaardag
  • 8.
  • 11.
  • 12. Properties public class ArrayList { public int Count {get;}} Property getters should be simple and therefore unlikely to throw exceptions Properties should not have dependencies on each other Setting one property should not affect other properties Properties should be settable in any order
  • 13. Properties versus Methods Use a Property: If the member logical attribute of the type Use a method: If the operation is a conversion,such as ToString() If the getter has an observableside effect If order of execution is important If the method might not return immediately If the member returns an array
  • 14. Properties and returning arrays public Employee[] All {get{}} public Employee[] GetAll() {} Calling Code EmployeeList l = FillList(); for (int i = 0; i < l.Length; i++){ if (l.All[i] == x){...} } if (l.GetAll()[i]== x) {...} Moral: Use method if the operation is expensive
  • 16. Extension Methods namespace 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”); }
  • 17. Extension methods marry the usability offered by object-oriented APIs with the flexibility of functional APIs.
  • 18. CONSIDER using extension methods to "add" methods to interfaces public interface IFoo{ void Bar(string x, bool y); void Bar(string x); } public static class IFooExtensions{ public static void Bar(this IFoo foo, string x){ foo.Bar(x,false); } } … IFoo foo = …; foo.Bar(“Hi!”);
  • 19. CONSIDER using extension methods to manage dependencies Uri uri = “ftp://some.ftp.uri”.ToUri(); // higher level assembly (not mscorlib) namespace System.Net { public static class StringExtensions{ public static Uri ToUri(this string s){ … } } }
  • 20. AVOID frivolously defining extension methods, especially on types you don’t own Might add clutter Choose namespaces for sponsor types carefully Remember that not all languages support extension methods Users will have to use static method call syntax
  • 21. AVOID defining extension methods on System.Object // C# declaration of the extension method public static class SomeExtensions{ static void SomeMethod(this object o){…} }   ‘ VB will try to find the method at runtime ‘ … but extension methods are resolved at ‘ compile time. Dim o As Object = … o.SomeMethod() ‘ THIS WILL THROW ‘ VB users will have to call the method using the regular static method call syntax. SomeExtensions.SomeMethod(o)
  • 24. Framework Design Theater The Main Character: Bright young developer The Setting: Her first big project The Setup: Create a class that models a car Actions required: Start and Drive
  • 25. Design Pass One: Meets Requirements Pass one: meets requirements
  • 26. Design Pass Two: More than Enough
  • 27. Design Pass Three: Way too much 25
  • 28. Time to Ship… Time to cut…
  • 29. What we ship: Too much and not enough… 27
  • 30. V.Next: Worse Yet Now we want to add Color and Model, and we know exactly how But it is much harder because the design is half done and mostly wrong
  • 31. The moral Do as little as possible now (but no less) to ensure room for extensibility in the future
  • 32. Abstract and Base classes Prefer broad, shallow hierarchies Less than or equal to 2 additional levels – Rough rule! Contracts and responsibilities are difficult to maintain and explain in deep complex hierarchies Consider making base classes not constructible (that is, use abstract classes) Make it clear what the class is for Provide a protected constructor for subclasses to call System.Exception should not have had a public constructor
  • 33. Virtual Method Example public class TheBase : Object { public override string ToString() { return “Hello from the Base"; } } public class Derived : TheBase { public override string ToString() { return “Hello from Derived"; } }
  • 34. Virtual Methods What is printed out? Derived d = new Derived();Console.WriteLine (d.ToString()); TheBase tb = d;Console.WriteLine (tb.ToString()); Object o = tb;Console.WriteLine (o.ToString());
  • 35. Virtual Methods They all output “Hello from Derived”. Why? Method call virtualizes at runtime The static type doesn’t matter This is the danger and power of virtual methods Danger: Owner of base classes cannot control what subclasses do Power: Base class does not have to change as new subclasses are created
  • 36. Overriding: Follow the Contract Don’t change the semantics of member Follow the contract defined on the base class All Virtual members should define a contract Don’t require clients to have knowledge of your overriding Should you call the base?
  • 37. Virtual and non-virtual Use non-virtual members unless you have specifically designed for specialization Have a concrete scenario in mind Write the code! Follow the Liskov Substitution Principle References to base types must work with derived types without knowing the difference Must continue to call in the sameorder and frequency Cannot increase or decrease range of inputs or output Barbara Liskov
  • 38. Interface Usage public interface IComparable { int CompareTo(object obj);} No common implementation (the ActiveX problem) Challenging to version over releases The smaller, more focused the interface the better 1-2 members are best But interfaces can be defined in terms of other simpler interfaces
  • 39. The great proof of madness is the disproportion of one's designs to one's means.Napoleon Bonaparte
  • 41. Type Dependency Management Careful dependency management is the necessary ingredient to successful evolution of frameworks. Without it, frameworks quickly deteriorate and are forced out of relevance prematurely.
  • 43. DO NOThave upward dependencies Avoidhorizontal dependencies WPF XML    BCL Reflection
  • 44. Libraries , Primitives, Abstractions
  • 45. CONSIDER placing library types higher on the dependency stack Definition: Library types are types that are not passed between components Examples EventLog, Debug, Easy to Evolve Leave old in, add new one Beware of duplication!
  • 46. DOkeep primitives policy free (i.e. simple) Definition: Primitive types are types that are passed between components and have very restricted extensibility (i.e. no subtype can override any members) Examples Int32, String, Uri. Hard to Evolve Little need to Evolve Typically in lower layers
  • 47. DO NOTcreate abstractions unless you know what you are doing Definition: Abstractions are interfaces or classes with unsealed members that are passed between components. Examples Stream, IComponent Hard to Evolve Unfortunately, pressure to evolve
  • 50. The Secret of Achiving Great Productivty A Pit!!
  • 51. The Pit of Success: in stark contrast to a summit, a peak, or a journey across a desert to find victory through many trials and surprises, we want our customers to simply fall into winning practices by using our platform and frameworks. To the extent that we make it easy to get into trouble we fail.- Rico Mariani
  • 52. Is using your framework correctly like… Climbing a mountain? 50
  • 53. Is using your framework correctly like… Scaling a peak? 51
  • 54. Is using your framework correctly like… Running across a desert? 52
  • 55. Is using your framework correctly like… Falling into a pit?
  • 56. Make using your framework as easy as falling into a pit – then you have achived great productivity
  • 58.
  • 59.
  • 60. 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); } }
  • 61. 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); … }
  • 62. Dependency Injection Containers // customer’s program that is even easier to test Tracer tracer = container.Resolve<Tracer>(); public void ProcessOrder(Order order){ tracer.Trace(order.Id); … } Check outDI Containers (a.k.a. IoC Containers):autofac, Castle Windsor, PicoContainer.NET, Spring.NET, StructureMap, Unity, and others.
  • 63. Tools
  • 65. Read the manual?? When you pick up your rental car…. Push the seat all the way back Find an NPR station Find the exit
  • 66. Oh, down to lock…
  • 67. How to use a key…
  • 68. Oh, you push the PRESS button…
  • 69. Who actually needs this data?
  • 70. Why you don’t read rental car manuals ??? 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… The Power of Sameness
  • 71. Naming Conventions PascalCasing – Each word starts with an uppercase letter camelCasing – First word lower case, others uppercase SCREAMING_CAPS – All upper case with underscores
  • 72. Naming Conventions All types and publicly exposed members are PascalCased Parameters are camelCased public class MemberDoc { public int CompareTo(object value) public string Name { get;} }
  • 73. Hungarian Notation Do not use Hungarian notation in publicly exposed APIs and parameter names public class CMyClass { int CompareTo (object objValue) {..} string lpstrName {get;} int iValue {get;} }
  • 74. On Abbreviations, acronym, initialism and the like… Avoid them! They are a classic JLT (jargon loaded term) OK to use them once they become words Html, Xaml, etc Don’t just spell them out Use a meaningful name Abbreviations of more than 2 letters are cased as words, otherwise ALLUPPER IO vs. Html
  • 75. While we are on naming… Good naming is hard—it takes time Be meaningful but brief Use US-English Colour vs. Color Principle of least surprise Look for prior-art NumberOfElements vs. Count
  • 76. FxCop – Keeping the "power of sameness" http://blogs.msdn.com/fxcop
  • 78. Framework Design Studio http://code.msdn.microsoft.com/fds
  • 79. Dependency Management Tools http://code.msdn.microsoft.com/fxarch Define Components <Group ID=“Component1”> <Bin Name=“MyCompany.FeatureA.dll”/> <Bin Name=“MyCompany.FeatureB.dll”/> </Group> Define Rules <Allow From=“Component1" To=“WPF"/> <Deny To=“XMLDOM”> Run and Get Output: From group Component1: MyCompany.FeatureA.dll should not depend on: SomeOtherComponent SomeOtherComponent.dll Also check out NDepend – a tool for visualizing dependencies.
  • 80. Summary 10 years of Framework design.. Core Principles of Framework design have stayed the same There are some significant new advances Check out the new book! Brad Abrams http://blogs.msdn.com/brada Twitter: @brada
  • 81. Q&A
  • 82. © 2008 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.
  • 83.
  • 84. Some images of movie posters sourced from www.imdb.com