From: David Vallner Date: 2006-10-29T01:10:00+09:00 Subject: Re: Class attribute unique to subclasses but used in parent class --------------enig821922CDE8F98FA062F0B73E Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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. >=20 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. Disclaimer: I am biased in favour of IoC and DI based "objects floating in vacuum" designs, especially for scenarios that involve reusing an expensive-to-create component like this one. If nothing else, declarative dependency resolution lets you plug in testing components easier / clearer than imperative (even if Ruby makes the latter easier in that you're allowed to molest any object in arbitrary ways.) David Vallner --------------enig821922CDE8F98FA062F0B73E Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFQ4DPy6MhrS8astoRAiJnAJ9CMYCCSLy+kvdYzNm29y2Yaxvi3gCdEQt+ 4shucofN8bArAIbkQr7tiFM= =BieB -----END PGP SIGNATURE----- --------------enig821922CDE8F98FA062F0B73E--