Create an Account
username: password:
 
  MemeStreams Logo

Day 19 -- Object-Oriented Programming in Perl -- Over-riding Subroutines

search

Lost
Picture of Lost
My Blog
My Profile
My Audience
My Sources
Send Me a Message

sponsored links

Lost's topics
Arts
Business
Games
Health and Wellness
Home and Garden
Miscellaneous
Current Events
Recreation
Local Information
Science
Society
Sports
Technology

support us

Get MemeStreams Stuff!


 
Day 19 -- Object-Oriented Programming in Perl -- Over-riding Subroutines
Topic: Technology 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);

Day 19 -- Object-Oriented Programming in Perl -- Over-riding Subroutines



 
 
Powered By Industrial Memetics
RSS2.0