Dart Classes - Factory Constructors

Поділитися
Вставка
  • Опубліковано 19 жов 2024

КОМЕНТАРІ • 72

  • @mostafaahmadi4998
    @mostafaahmadi4998 3 роки тому +25

    Dart developing team should put all of your videos on their website. The explanation of the factory constructor was amazing. Thank you

  • @kahanx10
    @kahanx10 2 роки тому +1

    I'm stunned by your comprehensiveness, I could not find so minute details explained about every topic and keyword elsewhere. You're a dart documentation in a human form.

  • @keithbertschin1213
    @keithbertschin1213 Рік тому

    Thank You so much for giving a real world example of what, to the newbie, is a complex subject.
    Many videos deal in the abstract that may show you what to do but miss out the why you’d want to do something.

  • @wabilemotswasele8705
    @wabilemotswasele8705 3 роки тому +1

    Thank you Johan. For the first time I have a proper understanding of factory constructors in Dart.

  • @2mvX
    @2mvX 2 роки тому

    Thanks man! 4 years of coding and now I found the purpose of factory constructor and finally understood this concept. Well explained!

  • @jimaustin3608
    @jimaustin3608 3 роки тому +1

    EXCELLENT tutorial; content thoroughly covered by good teacher! Thinking his ‘Flutter Course’ and ‘Dart Basic’ playlists look really good … and very current.

  • @venkatakhadri8998
    @venkatakhadri8998 2 роки тому

    Another excellent video tutorial explaining in a very simple way by Johan.

  • @billynyk
    @billynyk 3 роки тому

    Finally, watching this episode, I understand what the factory constructor is. Thanks.

    • @saurabhgaming1531
      @saurabhgaming1531 3 роки тому

      Can you help me how to add null safty in factory constructor plz plz

  • @aaliraza4004
    @aaliraza4004 2 роки тому

    most complete dart tutorials...thanks

  • @alfalarcon
    @alfalarcon 3 роки тому

    Great video!!! It is the best tutorial I have seen of the factory constructor.
    Thank you very much.

  • @wheatonrecurrence9525
    @wheatonrecurrence9525 3 роки тому

    Holy moly, this is such a good explanation.

  • @gumdum6764
    @gumdum6764 3 роки тому +2

    Thanks. It wasnt’ till the end of the tutorial that I understood what returning a sub-class instance of a class instead of the class itself meant. It was a light-bulb moment

  • @eliasyishak203
    @eliasyishak203 2 роки тому

    Very well done tutorial! Thank you!

  • @kholoudkhaled2897
    @kholoudkhaled2897 Рік тому

    First of all thank you for your effort
    I have a question, why declaring city and object variables out of the if statement but still inside for in loop give me an error

  • @obsessed92
    @obsessed92 2 роки тому

    Great example, thank you !

  • @raohamzanawab191
    @raohamzanawab191 2 роки тому

    what is the method of starting conversion with you

  • @eldarkurmakaev321
    @eldarkurmakaev321 2 роки тому

    Great video!

  • @venkatakhadri8998
    @venkatakhadri8998 2 роки тому

    Johan, I have been watching all your videos on your Dart and trying to practice also. At times, I need to refer back to previous video and code snippets. Is there is a gist or git that I can refer for all the code that was covered in the video tutorials. Thanks a bunch

    • @JohanJurrius
      @JohanJurrius  2 роки тому

      Hi, sorry. Not really for Dart. I tried to do it for Flutter.

  • @exconfessor3639
    @exconfessor3639 2 роки тому +2

    Link from the video: www.learndartprogramming.com/fundamentals/factory-constructor-in-dart/

  • @hiraokii
    @hiraokii 2 роки тому

    Hi sorry the question, but why the toString runs automatically?

    • @ParabTarak
      @ParabTarak Рік тому

      print(reading) basically calls toString method of the Reading and it's subclasses. This method returns a string. Since any object inherits Object class, you can override this method to return a custom string, as shown in the video. If you don't override it then it will print 'Instance of Reading' or 'Instance of Temperature' or 'Instance of Pressure' depending on the object type basically 'Instance of ' .
      tldr: print() method in the last for loop calls toString method of the readings, which prints the strings returned by the overridden toString methods of these readings.

  • @PamelaAnneHolmes
    @PamelaAnneHolmes 2 роки тому

    Thank you!

  • @asxes
    @asxes 2 роки тому

    awesome. thanks

  • @noeljriveropino5906
    @noeljriveropino5906 2 роки тому

    Hi Johan, maybe I couldn't find in your channel a video for generic classes, did you make one by any chance? Great video this one, by the way.

    • @JohanJurrius
      @JohanJurrius  2 роки тому +1

      I dont think so. Good one to add. thanks

    • @noeljriveropino5906
      @noeljriveropino5906 2 роки тому

      @@JohanJurrius Lots of people will appreciate it, i am 💯 sure

    • @noeljriveropino5906
      @noeljriveropino5906 2 роки тому

      @@JohanJurrius I will really appreciate it a lot.

  • @trapeye3464
    @trapeye3464 3 роки тому +2

    bro how u not famous.. the video so good lmao

    • @saurabhgaming1531
      @saurabhgaming1531 3 роки тому

      Can you help me how to add null safty in factory constructor plz plz

    • @trapeye3464
      @trapeye3464 3 роки тому

      @@saurabhgaming1531 i have similar problem at past.. i can help u.. if i remember the solution.. pm me?

    • @trapeye3464
      @trapeye3464 3 роки тому

      @@saurabhgaming1531 need to see the code

    • @trapeye3464
      @trapeye3464 3 роки тому

      @@saurabhgaming1531 wan_hahaha

    • @saurabhgaming1531
      @saurabhgaming1531 3 роки тому

      @@trapeye3464 bro I am unable to get your I'd plz hel me I cant share link here also it get automatically deleted after 29 sec

  • @lynnphoann
    @lynnphoann 3 роки тому

    nice explanation !!

  • @vgeniirshf8913
    @vgeniirshf8913 3 роки тому

    Thank you very much!

  • @homeofcreation
    @homeofcreation 3 роки тому

    fantasic video!

  • @trungledang5225
    @trungledang5225 3 роки тому

    Thanks you sir, resepect!

  • @saurabhgaming1531
    @saurabhgaming1531 3 роки тому

    Hello I am creating in latest versions but how to add null safty in factory constructor

    • @JohanJurrius
      @JohanJurrius  3 роки тому +1

      Could you give me an example of what you want to do in a gist and I can check if I can help?

    • @JohanJurrius
      @JohanJurrius  3 роки тому

      I will need to see your code

    • @JohanJurrius
      @JohanJurrius  3 роки тому +1

      You can create a gist on github. Really fast.

    • @saurabhgaming1531
      @saurabhgaming1531 3 роки тому

      I am un able to share link of gist yotube delete my comments plz help me

  • @yeayeayea7619
    @yeayeayea7619 5 місяців тому +3

    Hope this helps someone out:
    class Reading {
    double value;
    Reading({required double value}) : this.value = value;
    Reading.zero() : value = -999;
    @override
    String toString() {
    return '$value';
    }
    }
    class Temperature extends Reading {
    String city;
    Temperature({required String city, required double reading})
    : this.city = city,
    super(value: reading);
    Temperature.zero()
    : city = '',
    super(value: -999);
    @override
    String toString() {
    return 'Temperature reading:
    Reading: ${super.toString()}
    City: $city
    ';
    }
    }
    class Pressure extends Reading {
    String objectTested;
    Pressure({required String objectTested, required double reading})
    : this.objectTested = objectTested,
    super(value: reading);
    Pressure.zero()
    : objectTested = '',
    super(value: -999);
    @override
    String toString() {
    return 'Pressure reading:
    Reading: ${super.toString()}
    Object Tested: $objectTested
    ';
    }
    }
    void main() {
    var fromServer = [
    {
    'type': 'temp',
    'reading': 20.2,
    'city': 'Johannesburg',
    },
    {
    'type': 'pressure',
    'reading': 100.0,
    'object': 'Glass Cylinder',
    },
    {
    'type': 'temp',
    'reading': 35.2,
    'city': 'New York',
    },
    {
    'type': 'pressure',
    'reading': 300.5,
    'object': 'Tire',
    }
    ];
    }