Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: OOP - Sharing class methods

by lachoy (Parson)
on Aug 14, 2002 at 18:50 UTC ( [id://190189]=note: print w/replies, xml ) Need Help??


in reply to OOP - Sharing class methods

If the code can be used by both ClassOne and ClassTwo, why not make UtilityClassOne with this (and possibly other) methods that can be used by both? Inheritance is a possibility, but this doesn't sound like an 'is a' sort of relationship and IMO inheritance gets confusing if it's used in places where composition is more appropriate (e.g., 'has a').

Chris
M-x auto-bs-mode

Replies are listed 'Best First'.
Re: Re: OOP - Sharing class methods
by mp (Deacon) on Aug 14, 2002 at 19:09 UTC
    Wow! Thank you all for the quick responses. Using a utility class, as suggested by you and perrin, seems like an intuititive way of handling this problem in the general case, especially if the shared code were to use multiple objects.

    After thinking more about the specific application, I realized that there is already "a good fit" for the utility method in ClassThree because all the shared work is just calling a handful of existing instance methods in ClassThree. The new method then becomes a shortcut instance method that calls a number of its own instance methods.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://190189]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found