ã¢ã¯ã»ãµã®èªåçæ
æåã¯Javaã®ããªã§ã´ãªã´ãªã¨ã¢ã¯ã»ãµãæ¸ãã¦ããã§ãããCPANã®ã½ã¼ã¹èªãã§ã¦ãªãã»ã©Class::Accessor::Fastã使ãã°ããã®ãã¨ã
ãããã以ä¸ã®ããã«è¦ªã®Fooã¯ã©ã¹ã§ã¯ãnameãã ããFooãç¶æ¿ããFoo::Varã¯ã©ã¹ã§ã¯ãnameãã¨è¿½å ã§ãbirthdayãã®ã¢ã¯ã»ãµã使ãããã¨ããæãã§ä¾¿å©ã§ããã
package Foo; use base qw( Class::Accessor::Fast ); __PACKAGE__->mk_accessors( qw( name ) );
package Foo::Var; use base qw/ Foo /; __PACKAGE__->mk_accessors( qw( birthday ) );
ãã®ã¾ã¾ä½¿ãã¨getterã¯ã$self->get('name')ããã$self->nameããsetterã¯ãset('name', 'æ°ããåå'ãã¨ããæãã«ãªãã¾ããã
__PACKAGE__->follow_best_practice;
ã¨Perlãã¹ããã©ã¯ãã£ã¹æ¨å¥¨ã®å½¢ã«å¾ãããã«æå®ããã¨ãgetterã¯ã$self->get_nameããsetterã¯ã$self->set_name('æ°ããåå')ãã®ããã«ãget_ããset_ãï¼ãã¼ã®å½¢ã§è¨è¿°ããäºãå¼·å¶ãããããã«ãªãã¾ãã
ãã®å¶ç´ã¯è¦ªã¯ã©ã¹ã§æå®ããã¨ãã®ãµãã¯ã©ã¹ã«ãé©ç¨ããã¾ãã
ã¡ãªã¿ã«ãã®å¶ç´ã¯mk_accessorsã®åã«å¼ã³åºããªãã¨å¹ããªãã¿ããã§ãããä¸ç¬æ¸æãã¾ããã
ä»ã¾ã§ç§ãCPANã§èªãã éãã§ã¯å¿ ããããã®å¶ç´ã使ç¨ããã¦ããããã§ã¯ãªãã¦ãããã¯çµæ§å¥½ã¿ã®é¨åããã£ããããã®ããªãã¨ããæ°ããå人çã«ã¯å®è£ è ãåãã£ã¦ããããã°$self->nameã¨ãããæ¹ã好ã¿ããªãã¨ããæãã¯ãã¾ãã