| Recipe 10.2: Creating a 'Public' Attribute or Method |
Last Updated: Sep 8, 2003
Status: Draft
|
|
|
|
How important is this problem to you?
(Login to Vote)
5.00 Rating, 1 Vote
|
|
How acceptable is the proposed solution?
(Login to Vote)
0.00 Rating, 0 Votes
|
|
Problem:
   
You want to declare an attribute or method that available to all users of your class.
Solution:
Use the is public property:
has $counter is public;
method do_something is public { ... };
Discussion:
public is essentially the opposite of private: it provides unlimited access to an attribute or method. Use public attributes and methods to define how your class will be used by outsiders.
You cannot declare a symbol as both public and private.
By default, has declarations are assumed to be is private, and method declarations are assumed to be is public.
|