Create an Account
username: password:
 
  MemeStreams Logo

MemeStreams Discussion

search


This page contains all of the posts and discussion on MemeStreams referencing the following web page: Day 19 -- Object-Oriented Programming in Perl -- Over-riding Subroutines. You can find discussions on MemeStreams as you surf the web, even if you aren't a MemeStreams member, using the Threads Bookmarklet.

Day 19 -- Object-Oriented Programming in Perl -- Over-riding Subroutines
by Lost at 4:44 pm EST, Nov 9, 2007

Overrides

Sometimes you want to specify which class's method to use, such as when the same named method is specified in two different classes. For example, if the function grind is defined in both Espresso and Qava classes, you can specify which class's function to use by using the :: operator. The following calls would use the call in Espresso:

$mess = Espresso::grind("whole","lotta","bags");

Espresso::grind($mess, "whole","lotta","bags");

The following calls would use the grind() function in the Qava class:

$mess = Qava::grind("whole","lotta","bags");

Qava::grind($mess, "whole","lotta","bags");

You might want to call a method based on some action that the program you are writing has already taken. In other words, you want to use the Qava method for a certain condition and the Espresso method for another. In this case, you can use symbolic references to make the call to the required function, as in the following example:

$method = $local ? "Qava::" : "Espresso::";

$cup->{$method}grind(@args);


 
 
Powered By Industrial Memetics