[Learning] dart - Dart's metadata

I. Overview

  • Metadata Overview

    Metadata (Metadata), also known as intermediary data, relaying data, data describing data (data about data), mainly describing data attributes (property) of information, such as instructions to support the storage location, historical data, resource discovery , documentation and other functions.

  • Metadata definitions

    Metadata (the Metadata) data describing other data (data about other data), or data structure (structured data) for providing information to a resource. Metadata is data describing information resources or data objects, which use object: identifying a resource; Evaluation resources; track changes in resources during use; a simple and efficient management of a large number of network transactions; effective discovery information resources, Find, integration organizations and effective management of the use of resources. 

 

  • How metadata (the MetaData) understood
    Metadata is data that describes data (Data that describes other data). Just say, do not really understand, I give you an example.

    (She) old enough light, the three-ish, tall, tall, shapely, dark eyebrows, red face - in a word, not a girl, but jelly, she did active, noisy, constantly Russia humming a little song lyrics, loud laughter, quick to issue a series of loud laughter: ha, ha, ha! 
    
     This passage provides the several information: Age (III-ish), height (tall stature), appearance (shapely, dark eyebrows, red face), personality (active, noisy, non-stop humming little Russian ballad, loud laughter). With this information, we can roughly imagine Wa Lianka is what kind of person. By extension, as long as these types of information, we can also infer other people look.

    This example of "age", "height", "appearance", "character" is metadata, since they are used to describe data specific data / information / information.

Two, dart Metadata

  • Using the metadata to add more information to the code.
  • Metadata is the beginning @ modifier in the back @ compile-time constants or call followed a constant constructor.
  • Languages ​​currently offers three dart @ modifiers:
    • (Notes) - @deprecated be abandoned.  
      • Meaning : If after class or a method of adding the annotation indicating this method or class is no longer recommended, there will be strikethrough when you call, but it does not mean that can not just say, it is not recommended, because there are more method can be called good.
      • Role : because in a project, the project is relatively large, the code is more, and in the subsequent development process, a method previously possible implementation is not very reasonable, this time we must add a new method, whereas the previous method and not just deleted because it may have to call in other places, so add this comment, it is a convenient way to future developers call.
        class Television {
          @deprecated
          void activate(){
            turnOn();
          }
        
          void turnOn(){
            print('Television Turn On!');
          }
        
        }
        
        main(){
           dynamic tv = new Television();
           tv.activate();
           tv.turnOn();
        }

        Print Results:

        [Running] dart "/var/folders/l1/jvw4fvds26320gck06xj7xdh0000gn/T/tempCodeRunnerFile.dart"
        Television Turn On!
        Television Turn On!
    • (Notes) - @override rewritten.
      • Help yourself to check whether the correct replication of the existing parent class method
      • Tell people to read the code, which is a method of replication
        // Animal 
        class Animal {
             // animals eat 
            void EAT () { 
              Print ( " animals eat ' ); 
            } 
            // animals run 
            void RUN () { 
              Print ( " animals run ' ); 
            } 
        } 
        // human 
        class human the extends Animal {
           void say () { 
             Print ( ' people talking ' ); 
          } 
        
          void Study () { 
            Print ( ' human will eat ' ); 
          } 
        
          @override 
          voidEAT () { 
             Print ( ' human will eat ' ); 
          } 
        } 
        
        main () { 
          Print ( ' Examples of an animal ' );
           var Animal = new new Animal (); 
          animal.eat (); 
          animal.run () ; 
        
          Print ( ' example if a human ' );
           var human = new new human (); 
          human.eat (); 
          human.run (); 
          human.say (); 
          human.study (); 
        }
    • @proxy agent.

 

  • Define their own metadata

    • By librarydefining a library, a definition of the same name in the library class, and the class defined in the const constructor.  
      // 定义
      library todo;
       
      class todo {
        final String who;
        final String what;
       
        const todo(this.who, this.what);
      }
       
      // 使用
      import 'todo.dart';
       
      @todo('seth', 'make this do something')
      void doSomething() {
        print('do something');

Third, the summary

  Metadata can be modified following

    • library(Library), 
    • class(class), 
    • typedef(Type Definition), 
    • type parameter(Type parameter), 
    • constructor(Constructor), 
    • factory(Factory function), 
    • function(function), 
    • field(Scope), 
    • parameter(parameter),
    • variable declaration(Variable declarations).

Guess you like

Origin www.cnblogs.com/lxlx1798/p/11022305.html