| Recipe 1.1: Declaring a Class |
Last Updated: Sep 8, 2003
Status: Very Likely
|
|
|
|
How important is this problem to you?
(Login to Vote)
5.00 Rating, 7 Votes
|
|
How acceptable is the proposed solution?
(Login to Vote)
4.50 Rating, 6 Votes
|
|
Problem:
   
You want to declare a new object class for use in your program.
Solution:
   
Use the class keyword.
class MyClass; # (1) 'package-like'
class AnotherClass { # (2) explicit block
...
}
Discussion:
Class declarations in perl6 are accomplished via the class keyword. It may be used in two different ways:
If the declaration is followed by a code block, as in (2), the contents of the code block are treated as the implementation of the named class.
If the declaration is not followed by a code block, as in (1), class works similarly to module: it declares that whatever follows should be treated as the implementation of the named class, until the next class or module declaration, or until the end of the file is reached.
By convention, class names should begin with an uppercase letter. The root parent of all perl6 classes is the Object class; this allows all classes to contain certain "fundamental" attributes and methods.
|