Class Based OOP in Dart PRO

The Dart programming language uses classes and interfaces similarly to Java, C# and PHP. Dart supports single inheritance similarly to Java, C# and PHP. Dart supports multiple interfaces implementation similarly to Java, C# and PHP. As in Java and in C# every class inherits (by default) from the Object class. The classes can have public and private members. The public accessibility is the default one. Dart supports a special shorthand syntax for accessing class properties, similarly to properties in C#.

class Rectangle
{
  double _width;
  double _height;
  Rectangle(double w,double h)
  {
    width = w;
    height = h;
  }
  get width => _width;
  set width(size) => (size>0)?_width=size:_width=10.0;
  get height => _height;
  set height(size) => (size>0)?_height=size:_height=10.0;
  area() => width * height;
  perimeter() => 2*(width+height);
}

main()
{
  var ob = new Rectangle(3.2,4.4);
  ob.width = 20.2;
  ob.height = -4.1;
  var area = ob.area();
  print("area is $area");
}

The following video clip overviews this code sample, shows its execution and explains it.

Share:

banner for the css playlist in hebrew life michael courses for programmers

The First Steps in CSS

Learn CSS using our our videos (in Hebrew) on the CSS (he) playlist on youtube. Do it now. Do it for free.

Good Trainers Collaborate with Others

It is always essential to keep an open mind and learn from others. This applies to everyone, including teachers and especially software development trainers. Software

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences