I’ve posted this question before. Someone told me to see the RDoc of
ActiveRecord::Associations::ClassMethods, but I cannot find any
related information about multi-layer aggregation in this document.
This is what I’m doing now:
A “material” has “mechanical_feature”, “chemistry_feature”,
“physical_feature” and “technical_feature”. Each of these features has
different amount of properties such as “elastic_modulus”. I put all
these properties in the “material” table and use aggregation to
achieve the object model “material.mechanical_feature”. So “material”
extends “ActiveRecord::Base”, other composited classes
don’t.“mechanical_feature” has a series of “hardness” properties like
“rockwell_hardness”, “shore_hardness”, etc. They are mapping to the
corresponding columns of “material” table, of course. I’m thinking
that I should create a class “hardness” and put all these kind of
properties into it so that I can use
“material.mechanical_feature.hardness.rockwell” in my ruby code.
My question is that:
Since “mechanical_feature” is a composite class which doesn’t extend
“ActiveRecord::Base”, I suppose it cannot use the “composed_of”
method. Then how can I make “hardness” class aggregation? Some folks
told me that multi-layer aggregation is a ruby best-practice. Then how
can I achieve this?
Thanks a lot!