N00bie question. I'm working on a Class that has lots of attributes that
can be set or get. I've been using attr_accessor but am wondering if
there's a better way to store data. At this point I'm looking at two or
three dozen attributes and being extended as needed.
N00bie question. I'm working on a Class that has lots of attributes that
can be set or get. I've been using attr_accessor but am wondering if
there's a better way to store data. At this point I'm looking at two or
three dozen attributes and being extended as needed.
Sounds suspicious at first sight. Normally you don't have that many
attributes.
But that is a statistical characteristic of classes, not a hard rule. It
depends.
Knowing more about the class could help giving more concrete feedback. Coud
you paste some code? What is the class modelling? How does it look like?
I'm in the middle of adding another large number of attributes, and will
probably continue to add them. Hmm...I wonder if I can use hashes for
related data and cut down on the attr_accessor clutter.
···
On Mon, Nov 14, 2016 at 1:45 PM, Xavier Noria <fxn@hashref.com> wrote:
N00bie question. I'm working on a Class that has lots of attributes that
can be set or get. I've been using attr_accessor but am wondering if
there's a better way to store data. At this point I'm looking at two or
three dozen attributes and being extended as needed.
Sounds suspicious at first sight. Normally you don't have that many
attributes.
But that is a statistical characteristic of classes, not a hard rule. It
depends.
Knowing more about the class could help giving more concrete feedback.
Coud you paste some code? What is the class modelling? How does it look
like?
If this is for a game, the characters traits could be broken up into sub
groups and you could use structs or hashes in composition of the character
class. For example, all physical attributes could be in a "physical_traits"
struct, and skills could be in a skills struct. You then have accessors for
the structs in the character. You already seem to be doing this for
"Careers". Just extend it to the other attributes. You could then have
something like:
c = Character.new
# ...
character.physical.gender
character.skills.agility character.bio.name
character.inventory.cash
N00bie question. I'm working on a Class that has lots of attributes that
can be set or get. I've been using attr_accessor but am wondering if
there's a better way to store data. At this point I'm looking at two or
three dozen attributes and being extended as needed.
Sounds suspicious at first sight. Normally you don't have that many
attributes.
But that is a statistical characteristic of classes, not a hard rule. It
depends.
Knowing more about the class could help giving more concrete feedback.
Coud you paste some code? What is the class modelling? How does it look
like?
I'm in the middle of adding another large number of attributes, and will
probably continue to add them. Hmm...I wonder if I can use hashes for
related data and cut down on the attr_accessor clutter.
This is certainly the case for most OO data structures in this sort of environment. However, you are only replacing a multitude of attributes, with a multitude of sub-classes - it just makes it look simpler to get access to them, and provides more readable code. However, it is still vital to design the structures carefully as later changes can lead to an awful lot of work!
···
On 14/11/2016 7:06 PM, Raj Sahae wrote:
If this is for a game, the characters traits could be broken up into sub groups and you could use structs or hashes in composition of the character class. For example, all physical attributes could be in a "physical_traits" struct, and skills could be in a skills struct. You then have accessors for the structs in the character. You already seem to be doing this for "Careers". Just extend it to the other attributes. You could then have something like:
N00bie question. I'm working on a Class that has lots of
attributes that can be set or get. I've been using
attr_accessor but am wondering if there's a better way to
store data. At this point I'm looking at two or three
dozen attributes and being extended as needed.
Sounds suspicious at first sight. Normally you don't have that
many attributes.
But that is a statistical characteristic of classes, not a
hard rule. It depends.
Knowing more about the class could help giving more concrete
feedback. Coud you paste some code? What is the class
modelling? How does it look like?
I'm in the middle of adding another large number of attributes,
and will probably continue to add them. Hmm...I wonder if I can
use hashes for related data and cut down on the attr_accessor
clutter.
No virus found in this message.
Checked by AVG - www.avg.com <http://www.avg.com>
Version: 2016.0.7859 / Virus Database: 4664/13405 - Release Date: 11/13/16