Class terms in Dart

Letsgo

Some terms in Dart are a little bit confusing to newcomers including myself.

This is my understanding, but, I'm not sure wether it's right or not.

  1. members: variables in class including instance variables, static variables, constructors, static methods, and instance methods.
  2. properties: instance variables among members in a class and in an instance.
  3. fields: members except methods in a class.
  4. variable: denoting the name of an instance initialized, or an instance not yet initialized but with class definition including dynamic.
  5. functions: all terms those can have more than zero parameters, including methods.
  6. methods: functions defined and declared in a class including constructors, static methods.
  7. objects: all the terms in Dart except conjunctions(if, while, for ...) and adjectives(static, final...)

Second, are there terms distinguishing properties in a class(not yet initialized) and those in an instance(initialized)? That is to say, between initialized variables and not-yet initialized ones.

Third, is there any class hierarchy diagram for Dart? I have found a very simple one, but not like those of other languages.

Fourth, I have guessed the sentence (A) is derived from the sentence (B). Is it right?

(A) int x = 1;
(B) var x = int(1); //int() is the default constructor of class int. All the same to String, double, Map, List

...

I want to say thank you all for a few Korean students learning Dart.

Günter Zöchbauer
  1. members: variables in class including instance variables, static variables, constructors, static methods, and instance methods.
    • members are: fields (non-static variables declared in a class, properties are the same as fields), methods
      (fields/properties are also often called attributes but I think this should avoided in web development because attributes usually refers HTML attributes).
    • variables are not considered members except when they are fields
    • I would not consider static fields (properties/functions) members in Dart (but I'm not sure about this too). They are sometimes referenced as class members or static members but in Dart the class is merely as a namespace and these variables functions don't act like members.
    • constructors are not members
  1. properties: instance variables among members in a class and in an instance.
    • as far as I know are properties the same as fields. Often properties refers to getters/setters only but in Dart they are the same, at least at runtime (getters/setters are automatically created for all fields)
    • I'm not sure what you mean by class here. Class usually refers to statics (see above)
    • getters/setters (functions that can be accessed like fields) are usually seen as properties
  1. fields: members except methods in a class.
    • I would only call instance variables fields and static variables static fields
  1. variable: denoting the name of an instance initialized, or an instance not yet initialized but with class definition including dynamic.
    • variable is a declared identifier that refers a memory address no matter where (library, class, instance, function, method).
    • A not yet initialized variable refers no valid memory address ('null').
  1. functions: all terms those can have more than zero parameters, including methods.
    • The number of parameters is not relevant.
    • Functions can be called using () or (arg1, arg2, ...)
    • Non-static functions in a class are usually called method not function.
    • Functions are outside a class at library level, or within a method or function (not sure whether static methods are referred as function or method in Dart).
void someFunction() => doSomething();
void someFunction(int a) { doSomething(); }

class A {
  void someMethod() {
    var anonymousFunction = () {
      doSomething();
    };

    anonymousFunction();
  }
}
  1. methods: functions defined and declared in a class including constructors, static methods.
    • see above about static methods
    • constructors are not methods, constructors are constructors ;-)
  1. objects: all the terms in Dart except conjunctions(if, while, for ...) and adjectives(static, final...)
    • only instances of a class are objects
var a = new A();

new A(); creates an instance of A. a refers an instance of a (object).

var x = 5;

creates an instance of int and x refers this instance (object).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related