[Chicago-talk] Proper encapsulation

Jay Strauss me at heyjay.com
Fri Jan 21 22:01:56 PST 2005


Hi, I'm using Class::Accessor, it provides a method ->mk_accessors 
(which ironically creates setters and getters for your class).  Anyway, 
I think typically you'd invoke this from the class, but you can do it 
from the code that instatiates the class.

Like:

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

package SomeClass;

use base qw/Class::Accessor/;

package main;

SomeClass->mk_accessors(qw/cache/);

my $o = SomeClass->new;
$o->cache("data");

print $o->cache,"\n";


My question is: does creating the accessors from outside the class 
violate OO principles, or is acceptable since the functionality is provided?

Thanks
Jay


More information about the Chicago-talk mailing list