File: classes.dart.faceup

package info (click to toggle)
emacs-dart-mode 1.0.7%2Bgit20250811.edb45cb-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 656 kB
  • sloc: lisp: 613; makefile: 29
file content (31 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
«k:class» «t:Spacecraft» {
  «t:String» «v:name»;
  «t:DateTime» «v:launchDate»;

  «m:// »«x:Constructor, with syntactic sugar for assignment to members.
»  «t:Spacecraft»(«k:this».«v:name», «k:this».«v:launchDate») {
    «m:// »«x:Initialization code goes here.
»  }

  «m:// »«x:Named constructor that forwards to the default one.
»  «t:Spacecraft».unlaunched(«t:String» «v:name») : «k:this»(name, «c:null»);

  «t:int» «b:get» «v:launchYear» => launchDate?.year; «m:// »«x:read-only non-final property
»
  «m:// »«x:Method.
»  «t:void» «f:describe»() {
    print(«s:'Spacecraft: »«v:$name»«s:'»);
    «k:if» (launchDate != «c:null») {
      «t:int» «v:years» = «t:DateTime».now().difference(launchDate).inDays ~/ «c:365»;
      print(«s:'Launched: »«v:$launchYear»«s: (»«v:$years»«s: years ago)'»);
    } «k:else» {
      print(«s:'Unlaunched'»);
    }
  }
}

«k:var» «v:voyager» = «t:Spacecraft»(«s:'Voyager I'», «t:DateTime»(«c:1977», «c:9», «c:5»));
voyager.describe();

«k:var» «v:voyager3» = «t:Spacecraft».unlaunched(«s:'Voyager III'»);
voyager3.describe();