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

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

Issue 10788006: new site (Closed) Base URL: https://code.google.com/p/dartlang-site/@master
Patch Set: final patch 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 This section explains how to use 1 This section explains how to use
2 <a href="#libraries-import">import</a> (**#import**), 2 <a href="#libraries-import">import</a> (**#import**),
3 <a href="#libraries-source">include</a> (**#source**), 3 <a href="#libraries-source">include</a> (**#source**),
4 and <a href="#libraries-library">library</a> (**#library**) 4 and <a href="#libraries-library">library</a> (**#library**)
5 directives, 5 directives,
6 which can help you 6 which can help you
7 create a modular and shareable code base. 7 create a modular and shareable code base.
8 Libraries not only provide APIs, 8 Libraries not only provide APIs,
9 but are a unit of privacy: 9 but are a unit of privacy:
10 they can hide implementation details such as private variables. 10 they can hide implementation details such as private variables.
11 11
12 <b>Every Dart app is a library</b>, 12 <b>Every Dart app is a library</b>,
13 even if it doesn't use #library. 13 even if it doesn't use #library.
14 14
15 <aside class="note"> 15 <aside>
16 <b>Note:</b> 16 <div class="alert">
17 The library system in Dart <b>will change</b>. 17 <strong>Warning:</strong>
18 This section describes how it currently works. 18 The library system in Dart <b>will change</b>.
19 This section describes how it currently works.
20 </div>
19 </aside> 21 </aside>
20 22
21 23
22 <section id="libraries-import" markdown="1"> 24 <section id="libraries-import" markdown="1">
23 ### Using libraries 25 ### Using libraries
24 26
25 Use **#import** to 27 Use **#import** to
26 specify how a namespace from one library 28 specify how a namespace from one library
27 is used in the scope of another library. 29 is used in the scope of another library.
28 30
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 to specify that a file 84 to specify that a file
83 implements a library. 85 implements a library.
84 86
85 87
86 <section id="libraries-source" markdown="1"> 88 <section id="libraries-source" markdown="1">
87 #### Associating a file with the current library 89 #### Associating a file with the current library
88 90
89 You can put your library's implementation into multiple .dart files 91 You can put your library's implementation into multiple .dart files
90 by using **#source** in the library's main .dart file. 92 by using **#source** in the library's main .dart file.
91 93
92 <aside class="note" markdown="1"> 94 <aside>
93 **Included files can't have directives.** 95 <div class="alert alert-info">
94 A single file in each library 96 <strong>Tip:</strong>
95 must have all the directives (such as #import and #library) 97 Included files can't have directives.
96 that the library needs. 98 A single file in each library
99 must have all the directives (such as #import and #library)
100 that the library needs.
101 </div>
97 </aside> 102 </aside>
98 103
99 For example, consider the following code: 104 For example, consider the following code:
100 105
101 {% highlight dart %} 106 {% highlight dart %}
102 // in Ballgame.dart: 107 // in Ballgame.dart:
103 #import('dart:html'); 108 #import('dart:html');
104 109
105 #source('Ball.dart'); 110 #source('Ball.dart');
106 #source('Util.dart'); 111 #source('Util.dart');
107 ... 112 ...
108 main() { 113 main() {
109 ... 114 ...
110 } 115 }
111 {% endhighlight %} 116 {% endhighlight %}
112 117
113 In this example, Ball.dart and Util.dart are compiled into 118 In this example, Ball.dart and Util.dart are compiled into
114 the library Ballgame.dart. 119 the library Ballgame.dart.
115 Ballgame.dart doesn't have a #library statement, 120 Ballgame.dart doesn't have a #library statement,
116 but remember that each Dart app has an implicit library. 121 but remember that each Dart app has an implicit library.
117 122
118 123
119 <section id="libraries-library" markdown="1"> 124 <section id="declaring-library" markdown="1">
120 #### Declaring a library 125 #### Declaring a library
121 126
122 To explicitly declare a library, you use a **#library** statement. 127 To explicitly declare a library, you use a **#library** statement.
123 For example: 128 For example:
124 129
125 {% highlight dart %} 130 {% highlight dart %}
126 #library('slider_sample'); // Declare that this is a library. 131 #library('slider_sample'); // Declare that this is a library.
127 132
128 #import('dart:html'); // It uses the html library 133 #import('dart:html'); // It uses the html library
129 #import('../ui_lib/view/view.dart'); // and a view library. 134 #import('../ui_lib/view/view.dart'); // and a view library.
130 135
131 #source('SliderSample.dart'); // Grab the code from SliderSample.dart. 136 #source('SliderSample.dart'); // Grab the code from SliderSample.dart.
132 {% endhighlight %} 137 {% endhighlight %}
133 138
134 <aside class="note"> 139 <aside>
135 <b>Note:</b> 140 <div class="alert alert-info">
136 The string in the #library statement isn't currently used. 141 <strong>Note:</strong>
142 The string in the #library statement isn't currently used.
143 </div>
137 </aside> 144 </aside>
145
138 </section> 146 </section>
139 147
140 <section id="libraries-private-members" markdown="1"> 148 <section id="libraries-private-members" markdown="1">
141 #### Declaring private members 149 #### Declaring private members
142 150
143 If an identifier starts with an underscore, 151 If an identifier starts with an underscore,
144 it's private to its library. 152 it's private to its library.
145 For example, 153 For example,
146 in the following code, the Incrementer class 154 in the following code, the Incrementer class
147 has an instance variable 155 has an instance variable
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 203
196 <section id="libraries-summary" markdown="1"> 204 <section id="libraries-summary" markdown="1">
197 ### Summary of libraries and visibility 205 ### Summary of libraries and visibility
198 Use **#import** if you need to use a library, 206 Use **#import** if you need to use a library,
199 **\#source** to pull files into a library, 207 **\#source** to pull files into a library,
200 and **#library** to declare that you're implementing a library. 208 and **#library** to declare that you're implementing a library.
201 Names prefixed with underscore (_) are private to the library. 209 Names prefixed with underscore (_) are private to the library.
202 </section> 210 </section>
203 211
204 </section> 212 </section>
OLDNEW
« no previous file with comments | « src/site/_includes/language-tour/interfaces/index.markdown ('k') | src/site/_includes/language-tour/operators/index.markdown » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698