32. Classes and interfaces
i n t e r f a c e Shape {
num p e r i m e t e r ( ) ;
}
c l a s s R e c t a n g l e i m p l e m e n t s Shape {
f i n a l num h e i g h t , w i d t h ;
R e c t a n g l e (num t h i s . h e i g h t , num t h i s . w i d t h ) ;
// Compact c o n s t r u c t o r s y n t a x .
num p e r i m e t e r ( ) => 2* h e i g h t + 2* w i d t h ;
// S h o r t f u n c t i o n s y n t a x .
}
c l a s s Square extends Rectangle {
S q u a r e (num s i z e ) : s u p e r ( s i z e , s i z e ) ;
}
@yinhm Dart 16/27
33. Optional types
c l a s s Point {
var x , y ;
Point ( t h i s . x , t h i s . y ) ;
s c a l e ( f a c t o r ) => new P o i n t ( x * f a c t o r , y * f a c t o r ) ;
d i s t a n c e ( ) => Math . s q r t ( x * x + y * y ) ;
}
main ( ) {
v a r a = new P o i n t ( 2 , 3 ) . s c a l e ( 1 0 ) ;
print (a . distance ());
}
@yinhm Dart 17/27
34. Static types
c l a s s Point {
num x , y ;
P o i n t (num t h i s . x , num t h i s . y ) ;
P o i n t s c a l e (num f a c t o r ) => new P o i n t ( x * f a c t o r , y *
num d i s t a n c e ( ) => Math . s q r t ( x * x + y * y ) ;
}
v o i d main ( ) {
P o i n t a = new P o i n t ( 2 , 3 ) . s c a l e ( 1 0 ) ;
print (a . distance ());
}
@yinhm Dart 18/27
49. Links
• Dart 官网: http://www.dartlang.org/
• Intro to Dart
• Dart: a new programming language for structured web
• A Walk on the Dart Side
• Dart Technical Overview
@yinhm Dart 26/27
50. About
Created in L TEX using the beamer class, TeX Live and Emacs.
A
Published under the Creative Commons Attribution 3.0 License
http://creativecommons.org/licenses/by/3.0/
by @yinhm
http://yinhm.appspot.com
Document version February 25, 2012
@yinhm Dart 27/27