PC58
 Krzysztof Cwalina
Program Manager
Microsoft Corporation
http://blogs.msdn.com/kcwalina
 Brad Abrams
Product Unit Manager
Microsoft Corporation
http://blogs.msdn.com/brada
Dow Jones Industrial Average
@ 9,000
Dow Jones Industrial Average
@ 9,000


Framework Design
Artifacts:
• Properties
• Methods
• Events
• Constructors
lazy
public class XmlFile {
string filename;
Stream data;
public XmlFile(string filename) {
this.data = DownloadData(filename);
public XmlFile(string filename) {
}
this.filename = filename;
}
}



8
public class ArrayList {
public int Count {get;}
}












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


public static bool IsNullOrEmpty(this string s){
message.IsNullOrEmpty()

this IFoo foo
foo.Bar(“Hi!”);

“ftp://some.ftp.uri”.ToUri();
// higher level assembly (not mscorlib)






// C# declaration of the extension method
object
‘ VB will try to find the method at runtime
‘ … but extension methods are resolved at
‘ compile time.
‘ THIS WILL THROW
‘ VB users will have to call the method using the
regular static method call syntax.










24
Time to cut…
26









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";
}
}

Derived d = new Derived();
Console.WriteLine (d.ToString());
TheBase tb = d;
Console.WriteLine (tb.ToString());
Object o = tb;
Console.WriteLine (o.ToString());








All Virtual members should define a contract
Don’t require clients to have knowledge of
your overriding
Should you call the base?







Barbara Liskov
public interface IComparable {
int CompareTo(object obj);
}







Careful dependency management
is the necessary ingredient to
successful evolution of
frameworks. Without it,
frameworks quickly deteriorate
and are forced out of relevance
prematurely.


WPF

BCL

XML

Reflection

























: in stark contrast
to a summit, a peak, or a journey
across a desert to
and surprises, we want
our customers to
by using our
platform and frameworks. To the
extent that
.
- Rico Mariani
Climbing a mountain?
49
Scaling a
peak?
50
Running across a desert?
51
Falling into a
pit?






// your API
MessageQueue mq = new MessageQueue(…);
// your customer’s program that is hard to test
// your better API
abstract class TraceListener
TraceListener listener;
TraceListener listener
// your customer’s program that is easier to test
new FileListener()
// customer’s program that is even easier to test
container.Resolve<Tracer>();





Read the manual??





PascalCasing – Each
word starts with an
uppercase letter
camelCasing – First
word lower case,
others uppercase
SCREAMING_CAPS –
All upper case with
underscores


public class MemberDoc
{
public int CompareTo(object value)
public string Name { get;}
}

public class CMyClass {
int CompareTo (object objValue) {..}
string lpstrName {get;}
int iValue {get;}
}















http://blogs.msdn.com/fxcop


http://code.msdn.microsoft.com/fds
http://code.msdn.microsoft.com/fxarch

Group
Bin
Bin
Group

Allow
Deny






Brad Abrams
http://blogs.msdn.com/brada
Krzysztof Cwalina
http://blogs.msdn.com/kcwalina
www.microsoftpdc.com
© 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.
Descargar

PC58 – Framework Design Guidelines