From: dblack@... Date: 2006-10-29T01:17:19+09:00 Subject: Re: Class attribute unique to subclasses but used in parent class Hi -- On Sun, 29 Oct 2006, David Vallner wrote: > lcor1979@gmail.com wrote: >> What I'll like, is that Child1 and Child2 have their own values of >> @@test, but @@test should be initialized and used in Parent. >> Also, @@test cannot be an instance variable because it is heavy to >> initialize and will be common to all instances of Child1 or Child2. >> > > Class variables and class instance variables sound way too much like > global state coming into the system through a backdoor, I'd avoid both. > > Personally, I'd replace lookup through a class variable or class > instance variable with injecting the shared object into instances. The > less shared state, the more flexibility you gain in being able to rewire > your objects. Instance variables don't involve shared state, though; they're strictly per object (Class object or otherwise). David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org