Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/site/_includes/language-tour/interfaces/index.markdown

Issue 10700168: massive CL is massive (Closed) Base URL: https://code.google.com/p/dartlang-site/@master
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 Interfaces are types that define how you can interact with an object. 1 Interfaces are types that define how you can interact with an object.
2 An interface can specify methods, 2 An interface can specify methods,
3 constructors, 3 constructors,
4 instance variables 4 instance variables
5 (or, more precisely, getters and setters), 5 (or, more precisely, getters and setters),
6 and superinterfaces. 6 and superinterfaces.
7 It doesn't, however, specify the code _inside_ of 7 It doesn't, however, specify the code _inside_ of
8 methods and constructors. 8 methods and constructors.
9 9
10 Interfaces are handy for specifying APIs 10 Interfaces are handy for specifying APIs
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 Here's an example of 62 Here's an example of
63 specifying that a class implements multiple interfaces: 63 specifying that a class implements multiple interfaces:
64 64
65 {% highlight dart %} 65 {% highlight dart %}
66 class Point implements Comparable, Hashable { 66 class Point implements Comparable, Hashable {
67 ... 67 ...
68 } 68 }
69 {% endhighlight %} 69 {% endhighlight %}
70 70
71 <aside class="note" markdown="1"> 71 <aside>
72 **Note:** 72 <div class="alert alert-info">
73 Soon you'll be able to treat Dart classes as interfaces. 73 <strong>Tip:</strong>
74 This feature will be useful when creating mock objects for testing. 74 Dart classes have implicit interfaces.
75 This feature is useful when creating mock objects for testing.
76 </div>
75 </aside> 77 </aside>
76 78
77 </section> 79 </section>
78 80
79 81
80 <section id="interfaces-extending" markdown="1"> 82 <section id="interfaces-extending" markdown="1">
81 ### Extending an interface 83 ### Extending an interface
82 84
83 You can create an interface 85 You can create an interface
84 that builds on one or more interfaces. 86 that builds on one or more interfaces.
85 The new interface is called a _subinterface_, 87 The new interface is called a _subinterface_,
86 and all the interfaces it inherits from are its _superinterfaces_. 88 and all the interfaces it inherits from are its _superinterfaces_.
87 89
88 Use the **extends** keyword 90 Use the **extends** keyword
89 to specify which interface (or interfaces) you're adding to. 91 to specify which interface (or interfaces) you're adding to.
90 Here's an example of creating a subinterface of Hashable: 92 Here's an example of creating a subinterface of Hashable:
91 93
92 {% highlight dart %} 94 {% highlight dart %}
93 interface HashablePoint extends Hashable { 95 interface HashablePoint extends Hashable {
94 num x, y; 96 num x, y;
95 } 97 }
96 {% endhighlight %} 98 {% endhighlight %}
97 99
98 <aside class="note" markdown="1"> 100 <aside>
99 **Note:** 101 <div class="alert alert-info">
100 Technically, interfaces don't have instance variables 102 <strong>Note:</strong>
101 such as `x` and `y`. 103 Technically, interfaces don't have instance variables
102 What looks like an instance variable is really a 104 such as `x` and `y`.
103 shortcut for declaring 105 What looks like an instance variable is really a
104 [getter and setter methods](#classes-getters-and-setters). 106 shortcut for declaring
107 [getter and setter methods](#classes-getters-and-setters).
108 </div>
105 </aside> 109 </aside>
106 110
107 Here's an example of implementing a subinterface 111 Here's an example of implementing a subinterface
108 and checking types. 112 and checking types.
109 113
110 {% highlight dart %} 114 {% highlight dart %}
111 class Point implements HashablePoint { 115 class Point implements HashablePoint {
112 num x, y; // Required by HashablePoint 116 num x, y; // Required by HashablePoint
113 117
114 // Required by Hashable 118 // Required by Hashable
(...skipping 16 matching lines...) Expand all
131 {% endhighlight %} 135 {% endhighlight %}
132 </section> 136 </section>
133 137
134 138
135 <section id="interfaces-default-class" markdown="1"> 139 <section id="interfaces-default-class" markdown="1">
136 ### Defining constructors and a default class 140 ### Defining constructors and a default class
137 141
138 An interface can define constructors, 142 An interface can define constructors,
139 as long as it specifies a _default class_. 143 as long as it specifies a _default class_.
140 144
141 <aside class="note" markdown="1"> 145 <aside>
142 **Note:** 146 <div class="alert alert-info">
143 Many of the Dart APIs are implemented as 147 <strong>Note:</strong>
144 interfaces that have default classes. 148 Many of the Dart APIs are implemented as
145 For example, all of the <a href="#built-in-types">built-in types</a>, 149 interfaces that have default classes.
146 including <a href="#numbers">num and int</a>, are interfaces. 150 For example, all of the <a href="#built-in-types">built-in types</a>,
151 including <a href="#numbers">num and int</a>, are interfaces.
152 </div>
147 </aside> 153 </aside>
148 154
149 Use the `default` keyword to specify 155 Use the `default` keyword to specify
150 the default class. 156 the default class.
151 For example: 157 For example:
152 158
153 {% highlight dart %} 159 {% highlight dart %}
154 interface ObjectCache default MemoryCache { 160 interface ObjectCache default MemoryCache {
155 ObjectCache(); 161 ObjectCache();
156 // ... 162 // ...
(...skipping 23 matching lines...) Expand all
180 186
181 187
182 <section id="interfaces-summary" markdown="1"> 188 <section id="interfaces-summary" markdown="1">
183 ### Summary of interfaces 189 ### Summary of interfaces
184 Interfaces are everywhere in Dart, 190 Interfaces are everywhere in Dart,
185 from built-in types to 191 from built-in types to
186 many of the types defined in the standard Dart libraries. 192 many of the types defined in the standard Dart libraries.
187 Because Dart interfaces can have default classes, 193 Because Dart interfaces can have default classes,
188 you can use interface constructors. 194 you can use interface constructors.
189 </section> 195 </section>
OLDNEW
« no previous file with comments | « src/site/_includes/language-tour/generics/index.markdown ('k') | src/site/_includes/language-tour/libraries/index.markdown » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698