Perl6 Object Oriented Cookbook (v0.2.1)  
Section 2: Attributes and Methods  
 
Recipe 2.10: 'Finalizing' the Implementation of a Method
Last Updated: Sep 8, 2003
Status: Draft
      Previous Page   Next Page

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

How acceptable is the proposed solution?
  (Login to Vote)
5.00 Rating, 2 Votes  

Problem:  

You want to prevent subclasses -- or anyone else -- from changing the implementation of a method.

Solution:  

Use the is final property:

method do_something(...) is final { ... }

Discussion:

There are circumstances in which you know the implementation of a method will never change; at least, you hope it won't, and you want perl to catch any attempts to override the method. That's what the is final does: it enforces the "finality" of a the method, such that the implementation given to the method may not be overriden.

Note that is final is very different from is interface. The is interface property declares that the interface, or signature of the method may not be altered. The is final property declares that the implementation of the method may no longer be altered.

Thus, is final implies is interface, but the reverse is not true.


Log In to Comment


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