Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Have you read the original "traits" paper?

but now how do I write my other classes against this role?
Other code should be written to use only the API provided by the RemoteConnection role, without caring what class it is otherwise. Any type checking should use the role name.

but then I can't easily inherit from both of them in Server and Client.
That sounds like a different problem. Maybe you didn't explain it well? Are you saying that Server and Client each want a different derived class of the Connection, but the Connection may already be different concrete classes?

You need to aggregate rather than further derive. Have the Connection class that you will be deriving from contain a SSH or Socket back-end instance, rather than being derived from it.

In fact, you might not need inheritance in the other place, either. Look at using collaborating instances instead. You can use delegation to make the result just as slick as inheritance rather than having to forward everything all over the place. Delegation can easily behave like inheritance from a run-time specified instance.

See this node for more recent discussion on delegation.


In reply to Re: Inherit from a Role (or something like that) by John M. Dlugosz
in thread Inherit from a Role (or something like that) by elTriberium

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-18 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found