September 2017
Beginner
402 pages
9h 52m
English
In the previous code, the address of a house was a free-text string. In more complex applications, it is better to keep addresses as a set of different fields—country, town, zip code, street name, and house number.
One of the possible implementations is adding more attributes to the House class:
class House { has Int $.rooms is rw where {$_ > 0}; has Real $.area is rw where {$_ > 0}; has Real $.height is rw where {$_ > 3}; has Int $.husenumber is rw where {$_ ne ''}; has Int $.zipcode is rw where {$_ > 0}; has Str $.country is rw where {$_ ne ''}; has Str $.town is rw where {$_ ne ''}; has Str $.street is rw where {$_ ne ''};}
It works but is not the best solution. Address details may be kept together in ...
Read now
Unlock full access