Dart 07 Connector and language learning package

Dart language learning 08

Author : ScorpioDong

1. Interface

Interface defines the syntax of any entity that must be followed. Interface defines a set of methods available objects.
Dart no syntax interface declaration. Dart is the class declaration in the interface itself.

Should my class implements keyword to use interface. Specific implementation class must provide all the functions of the interface has been achieved. In other words, the class must redefine interfaces it wishes to achieve each function.

main(List<String> args) {
    // 使用接口A的对象引用实现接口A的C类对象
    A obj1 = new C();
    obj1.aTest();

    // 使用接口B的对象引用实现接口B的C类对象
    B obj2 = new C();
    obj2.bTest();
}
// 定义接口A
class A {
    void aTest() {}
}

// 定义接口B
class B {
    void bTest() {}
}

// 定义类C实现接口A和B
class C implements A, B {
    // 重写A接口方法
    @override
    void aTest() {
        print("aTest");
    }

    // 重写B接口方法
    @override
    void bTest() {
        print("bTest");
    }
}

carried out

aTest
bTest

2 bags

Package A package is a set of programmed cell mechanisms. Applications may be necessary to integrate some third-party libraries or plug-ins. Each language has a mechanism to manage external packages, such as Maven或Gradle for Java, Nuget for .NET, npm for Node.jsand so on. Dart package manager is Pub.

Hosting packages repository can be found in https://pub.dartlang.org/.

Package metadata in the file pubspec.yamldefinition. YAML is a readable line height, used to express serialized data format.

PubTools are available for all the various libraries required to download the application.

pubspec.yamlContents of the file should look like this:

name: TestApp 
version: 0.0.1 
description: A Simple Application. 

dependencies: 
    xml: ^3.7.0

Package source pub tool in foreign countries, there may be instances of failure to obtain, where you can use the mirror open source Tsinghua University provided on the mirror.

echo 'export PUB_HOSTED_URL="https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"' >> ~/.bashrc

Terminal performs pub getto ensure that pubspec.yamlthe current path of the file.

❯ pub get
Resolving dependencies... (4.3s)
+ charcode 1.1.3
+ collection 1.14.12
+ convert 2.1.1
+ meta 1.1.8
+ petitparser 3.0.1
+ typed_data 1.1.6
+ xml 3.7.0
Downloading xml 3.7.0...
Downloading petitparser 3.0.1...
Downloading convert 2.1.1...
Downloading charcode 1.1.3...
Downloading meta 1.1.8...
Downloading typed_data 1.1.6...
Downloading collection 1.14.12...
Changed 7 dependencies!

Dependencies succeed, you can reference the package in the code file header.

import 'package:xml/xml.dart' as xml;
pub commonly used commands
command description
pub get Get the desired application dependencies
pub upgrade Will all depend upgrade to a newer version
pub build For building your web application, creates a build folder contains all the relevant script
pub help Provide help command pub
Published 59 original articles · won praise 45 · views 20000 +

Guess you like

Origin blog.csdn.net/m0_37771142/article/details/105036427