Classes in OO models are often a simple aggregates of attributes and methods.
-By default, the `new` construction require a value for each attribute defined in a class without a default value.
+By default, the `new` construction requires a value for each attribute defined in a class without a default value.
~~~
class Product
## Uncollected attributes
-There is three cases for an attributes to not be collected in the `new`.
+There are three cases for which an attribute is not collected in a `new` construction.
* Attributes with a default value
* Attributes with the annotation `noinit`
## Generalized initializers
-Initializers are methods that are automatically invoked by the new.
-In fact, by default, the setter of an attribute is used as a initializer.
+Initializers are methods that are automatically invoked by `new`.
+In fact, by default, the setter of an attribute is used as an initializer.
`autoinit` is used to register a method as a setter.
assert fp.z == 13
~~~
-Generalized setters are a powerful tool but often needed in only rare specific cases.
-In most case, there is no reason that an argument of a `new` construction is not stored in the object as a real attribute.
+Generalized setters are a powerful tool, but only needed in rare specific cases.
+In most cases, there is no reason for an argument of a `new` construction to not be stored in the object as a real attribute.
## Inheritance
end
var mp = new MultiProduct("ABC", "Bla bla", 15.96, 1, 3)
assert mp.id == "ABC"
-assert mp.price == 159.6
-assert mp.total_price == 175.4
+assert mp.price.is_approx(159.6, 0.001)
+assert mp.total_price.is_approx(175.4, 0.001)
assert mp.z == 13
~~~
redef fun to_s do return "({x},{y})"
end
var p1 = new Point(1.0, 2.0)
-assert p1.to_s == "(1,2)"
+assert p1.to_s == "(1.0,2.0)"
var p2 = new Point.origin
-assert p2.to_s == "(0,0)"
+assert p2.to_s == "(0.0,0.0)"
var p3 = new Point.polar(1.0, 2.0)
-assert p3.to_s == "(-0.4161,0.9092)"
+assert p3.to_s == "(-0.416,0.909)"
~~~
## `new` factories
-`new` factories permit to completely shortcut the class instantiation mechanim.
+`new` factories allow to completely shortcut the class instantiation mechanism.
It could be used to provide `new` syntax on non-concrete class (mainly `extern class`).
`new` factories behave like a top-level function that return the result of the construction.