Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^4: Can't locate object method- Issue

by perl_noobie (Initiate)
on Sep 28, 2013 at 12:45 UTC ( #1056126=note: print w/replies, xml ) Need Help??

in reply to Re^3: Can't locate object method- Issue
in thread Can't locate object method- Issue

Is there any way that a role can be removed after being assigned to a object? In my case, I would like to have a role assigned to an object, but during the course of the script, my roles for the particular object need to be modified. I want to remove the earlier role and add a new role to the object. Is there a way to do this?
  • Comment on Re^4: Can't locate object method- Issue

Replies are listed 'Best First'.
Re^5: Can't locate object method- Issue
by Corion (Pope) on Sep 28, 2013 at 12:54 UTC

    This sounds like horribly bad design.

    You haven't told us what problem you are trying to solve by this approach, but from my perspective, it looks as if your approach would be far better served by an object A that has another object B, which gets removed or replaced by a third object C if its behavirour needs to change:

    A -> B # Change behaviour: A -> C

    Maybe, B and C can implement some roles, but the interface of A should remain identical and delegate to its worker, B or C.

      Well, that's a classic OO pattern (delegation), but IMHO having whole objects just to contain a subset of behavior is overkill. Roles are packages of behavior explicitly.

      I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

        Certainly, but at least to my superficial understanding of Roles, you are not supposed to change your mind after the fact. Once you've mixed together some Roles in a class, you are not supposed to change the class further, or even worse, make changes on a per-object basis.

        If you need to dynamically change the class hierarchy/composition, or need to change the behaviour on a per-object basis, in my opinion, you should look at using objects that delegate to other objects instead.

        Meta: I came back to this comment due to the (maybe continued) discussion of the topic in 1056122.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056126]
[Corion]: And the second rule that I've learned is, that there is no one-off job, so writing a program for it pays off almost immediately. The third rule is to give all my programs numbers and have them reproduce that number in the name of their output files. :)
[Discipulus]: the true part is that also specification change between years.. but well our job is cheap but dont abuse of us.. ;=)
[LanX]: Choroba: do you miss chaos with ties? apply at the US government.. ;)
[ambrus]: Corion: those are good rules.
[ambrus]: Discipulus: oh sure. the input data has different filenames every time I get them.
[ambrus]: the directory structure may be 1, 2, or 3 deep, it may have spaces in the filename or not, it has dates in various format, different keywords for the same meanings, and the dates and other keywords are assembled in various ways.
[Discipulus]: no ambrus by specification i mean for example license per core instead of per socket, so fields are different

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2017-03-29 12:12 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (350 votes). Check out past polls.