On Mon, Nov 28, 2011 at 5:08 PM, Erik Colson <e...@ecocode.net> wrote:
> I have two classes : Employee and Department > every Employee works for at least one department. Sometimes the cost is > distributed over 2 or more departments. So I'd want a hashref inside the > Employee in which the keys are Department instances and the value a > percentage to be attributed to that Department. > No, what you want is an abstraction. Basically you're trying to hack in something that's actually business-information connecting several objects. In relational databases, you know it'd be wrong to do something like this in the employee table; the principle is much the same here. Maybe add an extra class WorksFor[1] containing the cost and department, and have a list of WorksFor in employee. (Warning, very little thought went into this and all my brain-blood is occupied around full stomach, but it solves the basic problem :) ) PS: When you're exposing hash/array-references to users of your class, you're begging for problems down the road - always[2] encapsulate implementation. [1] I suck at naming [2] Always doesn't always mean always. -- Lars Balker Rasmussen Consult::Perl