| |
| Recipe 3.10: Changing an Attribute to a Method, or Vice Versa |
Last Updated: Sep 8, 2003
Status: Draft
|
|
|
|
How important is this problem to you?
(Login to Vote)
4.33 Rating, 3 Votes
|
|
How acceptable is the proposed solution?
(Login to Vote)
3.00 Rating, 1 Vote
|
|
Problem:
   
You are inheriting from a class that has a .foo attribute: you want your subclass to implement .foo as an algorithm, not a simple value.
Solution:
 
Just do it:
class MyClass {
has int $.foo = 0;
}
class DerivedClass {
method int foo { ... }
}
Discussion:
(Need info from Apoc6)
Issue:
There may a subtle problem with the whole attribute/method symmetry thing when you are attempting to store an anonymous method in an attribute. Not that you couldn't do it, but would the behavior be transparent?... I have to think about it a bit more.
|
|