Tuesday, March 27, 2012

Overloading, what do'esw it mean? mitä se tarkoittaa, DART ym. kielet

Like most dynamically-typed languages, Dart doesn't support overloading....

http://japhr.blogspot.com/2012/02/overloading-dart-operators-for-great.html
Overloading Dart Operators for Great Evil

http://en.wikipedia.org/wiki/Overloading

Constructor and function/method overloading, in computer science, a type of polymorphism where different functions with the same name are invoked based on the data types of the parameters passed
Operator overloading, a form of functional or method overloading where the action being overloaded is an operator, such as + or -

http://www.parashift.com/c++-faq-lite/operator-overloading.html

It allows you to provide an intuitive interface to users of your class, plus makes it possible for templates to work equally well with classes and built-in/intrinsic types.
Operator overloading allows C/C++ operators to have user-defined meanings on user-defined types (classes). Overloaded operators are syntactic sugar for function calls...



Ja tähän Dart-kielestä esimerkkejä...



Function Overloading - General Dart Discussion | Google Groups
Oct 30, 2011 ... I'm progamming complex object and I am a little dissapointed with some aspect like it haven't got Methods Overloading. I think here could be ...
LabeledDiscussions
Constructor overloading - General Dart Discussion | Google Groups
Feb 12, 2012 ... Subject: Constructor overloading ... Why Dart doesn't allow to overloadconstructors. I have to define ... Subject: Re: Constructor overloading ...
LabeledDiscussions
Operator Overloading: "Convert" Operator - General Dart Discussion ...
Feb 13, 2012 ... I have seen this in other languages as an overloading of the "Convert" operator. Is this possible in Dart? For example: class Material{ ... } ...
LabeledDiscussions

http://www.dartlang.org/articles/idiomatic-dart/

Named constructors

Like most dynamically-typed languages, Dart doesn't support overloading. With methods, this isn't much of a limitation because you can always use a different name, but constructors aren't so lucky. To alleviate that, Dart lets you define named constructors:
class Point {
  num x, y;
  Point(this.x, this.y);
  Point.zero() : x = 0, y = 0;
  Point.polar(num theta, num radius) {
    x = Math.cos(theta) * radius;
    y = Math.sin(theta) * radius;
  }
}
Here our Point class has three constructors, a normal one and two named ones. You can use them like so:
var a = new Point(1, 2);
var b = new Point.zero();
var c = new Point.polar(Math.PI, 4.0);
Note that we're still using new here when we invoke the named constructor. It isn't just a static method.
.     originally published in   etdart.blogspot.fi  

No comments:

Post a Comment