Perl6 Object Oriented Cookbook (v0.2.1)  
Section 1: Introduction to Object Oriented Perl6  
 
Recipe 1.4: Declaring Attributes
Last Updated: Sep 8, 2003
Status: Very Likely
      Previous Page   Next Page

How important is this problem to you?
  (Login to Vote)
5.00 Rating, 5 Votes  

How acceptable is the proposed solution?
  (Login to Vote)
3.60 Rating, 5 Votes  

Problem:  

You want to declare an attribute of a class.

Solution:  

Use has:

class MyClass {
    has $.counter;
}

Discussion:

The has keyword allows you to declare attributes of a class.

See later recipes for declaring attributes as specific types, providing initial values to attributes, and for getting and setting attribute values.


Log In to Comment


Login / Edit User Info -- Copyright © 2002 Cognitivity -- Previous Page   Next Page