Skip to content

Commit

Permalink
class modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Apr 8, 2024
1 parent 85f1233 commit ca7247f
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
20 changes: 20 additions & 0 deletions learn_dart/test/types/class-modifiers/base.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ignore_for_file: unnecessary_type_check

import 'dart:core';

import 'package:test/test.dart';

void main() {
group("base ", () {
test("description", () {});
});
}

base mixin BaseMixin {}
base class BaseClass {}

// base具有传播性,父类base,子类也必须base
base class AA with BaseMixin {}

// base具有传播性,父类base,子类也必须base
base class ImplA implements BaseMixin {}
10 changes: 10 additions & 0 deletions learn_dart/test/types/class-modifiers/base_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'base.dart';

// 编译错误无法implement一个base mixin 或class
// 非常棒,这就是要的效果
// base class ImplA implements BaseMixin {}
// base class ExtendBaseClass implements BaseClass {}

base class WithBaseMixin with BaseMixin {}

base class ExtendBaseClass extends BaseClass {}
29 changes: 29 additions & 0 deletions learn_dart/test/types/class-modifiers/interface.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ignore_for_file: unnecessary_type_check

import 'dart:core';

import 'package:checks/checks.dart';
import 'package:test/test.dart';

void main() {
group("interface ", () {
test("description", () {
A a = A();
check(a.x()).equals("x");
AA aa = AA();
check(aa.x()).equals("x");

});
});
}

interface class A {
x() => "x";
}
class AA extends A {
}
// implements 就得实现父类所有方法
class ImplA implements A {
@override
x() => throw UnimplementedError();
}
24 changes: 24 additions & 0 deletions learn_dart/test/types/class-modifiers/mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ignore_for_file: unnecessary_type_check

import 'dart:core';

import 'package:test/test.dart';

void main() {
group("base ", () {
test("description", () {});
});
}

mixin A {
x() => "x";
}

// base具有传播性,父类base,子类也必须base
class AA with A {}

// base具有传播性,父类base,子类也必须base
class ImplA implements A {
@override
x() => throw UnimplementedError();
}
24 changes: 24 additions & 0 deletions learn_dart/test/types/class-modifiers/sealed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ignore_for_file: unnecessary_type_check

import 'dart:core';

import 'package:test/test.dart';

void main() {
group("base ", () {
test("description", () {});
});
}

sealed class A {
x() => "x";
}

// base具有传播性,父类base,子类也必须base
class AA extends A {}

// base具有传播性,父类base,子类也必须base
class ImplA implements A {
@override
x() => throw UnimplementedError();
}
6 changes: 6 additions & 0 deletions learn_dart/test/types/class-modifiers/sealed_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

// 编译错误,sealed 的类无法被继承或实现
// class ImplA implements A {
// }
// class WithA extends A {
// }

0 comments on commit ca7247f

Please sign in to comment.