官术网_书友最值得收藏!

Chapter 3. Structuring Code with Classes and Libraries

In this chapter we will look at the object-oriented nature of Dart. If you have prior knowledge of an OO language, most of this chapter will feel familiar. Nonetheless, coding classes in Dart is more succinct when introducing some nice new features such as factory constructors and generalizing the use of interfaces. If you come from the JavaScript world, you will start to realize that classes can really structure your application.

Data mostly comes in collections. Dart has some neat classes to work with collections, and they can be used for any type of collections. That's why they are called generic. As soon as you get a few code files in your project, structuring them by making libraries becomes essential for code maintainability. Also, your code will probably use existing libraries written by other developers; to make it easy, Dart has its own package manager called pub. Automating the testing of code on a functional level is done with a built-in unit test library.

We will look at the following topics:

  • Using classes and objects
  • Collection types and generic classes
  • Structuring your code using libraries
  • Managing library dependencies with pub
  • Unit testing in Dart

We will wrap it all up in a small but useful project to calculate word frequencies in an extract of text.

主站蜘蛛池模板: 响水县| 临泉县| 华容县| 盐津县| 泊头市| 盐山县| 白水县| 龙州县| 黔江区| 霍林郭勒市| 玉田县| 忻城县| 乐清市| 大安市| 手游| 松潘县| 遂昌县| 阿合奇县| 丹东市| 松潘县| 印江| 安徽省| 三门峡市| 襄城县| 黔西| 双峰县| 石嘴山市| 扶沟县| 兖州市| 大理市| 托里县| 固镇县| 萝北县| 临邑县| 乌拉特后旗| 那坡县| 延津县| 宾阳县| 信阳市| 桃园县| 武冈市|