# OO Thinking - First Attempt at building an object

**URL:** <https://www.ruby-forum.com/t/oo-thinking-first-attempt-at-building-an-object/62114>\
**Category:** Ruby\
**Created:** [May 31, 2006, 5:55pm UTC](https://www.ruby-forum.com/t/oo-thinking-first-attempt-at-building-an-object/62114 "2006-05-31T17:55:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_DSKraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@Paul\_DSKraus](https://www.ruby-forum.com/u/Paul_DSKraus)\
**Post date:** [May 31, 2006, 5:55pm UTC](https://www.ruby-forum.com/t/oo-thinking-first-attempt-at-building-an-object/62114/1 "2006-05-31T17:55:53Z")

</div>

Objective: store sales & units sold information by vendor, by year, by  
month, by class code.

In my nested data structured brain i see it like this

hash{vendor}{year}{month}[0…5][0…1]

0…5 = represent 6 different item classification codes  
0…1 = represents qty, sales.

I keep trying to write the pseudo code for an object and keep ending up  
with  
1 attribute that is the above data structure. Which kind of defeats the  
purpose.

Maybe a nested data structure is really the way to go with this?  
Or an object for each (vendor,year,month) that just increments or  
decrements  
the values. So my attribute would just  
be array\_class[0…5][0…1].

Still seems messy and overcomplicated.

Thoughts?

Please don’t write the class just help me sketch this out. My brain just  
is  
not use to the whole OO thing 🙂

Paul

---

<div class="post-metadata">

**Author:** ![Paul\_DSKraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@Paul\_DSKraus](https://www.ruby-forum.com/u/Paul_DSKraus)\
**Post date:** [May 31, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/oo-thinking-first-attempt-at-building-an-object/62114/2 "2006-05-31T18:18:04Z")

</div>

On May 31, 2006, at 11:55 AM, Paul D. Kraus wrote:

> I keep trying to write the pseudo code for an object and keep
> 
> Still seems messy and overcomplicated.
> 
> Thoughts?
> 
> Please don’t write the class just help me sketch this out. My brain  
> just is  
> not use to the whole OO thing 🙂
> 
> Paul

I usually try to build OO systems that parallel the actual items or  
events in a system. So for something like this, I’d first make an  
“Item” class which would contain vitals about a specific unit  
(vendor, model, etc…) There could be many of these objects (one  
for each unit) or not so many (one for each type of unit, though  
“ItemType” might be a better name then)

Then another class called something like “SalesRecord” which would  
contain the time and date of the sale, and an identifier (id, index,  
mac address) for which unit was sold.

If you want to look this all up, I recommend using ActiveRecord and  
tying all this to a database (SalesRecord has an item). Then you can  
look up by anything.

But there’s always more than one way to skin a cat.  
-Mat

---

<div class="post-metadata">

**Author:** ![Paul\_DSKraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@Paul\_DSKraus](https://www.ruby-forum.com/u/Paul_DSKraus)\
**Post date:** [May 31, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/oo-thinking-first-attempt-at-building-an-object/62114/3 "2006-05-31T18:24:42Z")

</div>

On May 31, 2006, at 10:55 AM, Paul D. Kraus wrote:

> I keep trying to write the pseudo code for an object and keep
> 
> Still seems messy and overcomplicated.
> 
> Thoughts?
> 
> Please don’t write the class just help me sketch this out. My brain  
> just is  
> not use to the whole OO thing 🙂

Classes are data, wrapped up with the behaviors for that data.  
You’ve already laid out the data, so I’m just repeating you:

- vendor
- year
- month
- classification code
- quantity
- sales

Possible behaviors might be verifying that a classification code is  
legal when it is set, for example.

Now, if you have all these objects in an Array, you can always find()  
(Hint, hint!) them by any criteria you need, right?

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![Paul\_DSKraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@Paul\_DSKraus](https://www.ruby-forum.com/u/Paul_DSKraus)\
**Post date:** [May 31, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/oo-thinking-first-attempt-at-building-an-object/62114/4 "2006-05-31T18:27:48Z")

</div>

On 5/31/06, Paul D. Kraus [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I keep trying to write the pseudo code for an object and keep ending up with  
> Thoughts?  
> There is one store  
> The store has many vendors  
> Vendors have many products  
> The store has many sales (of its vendors products)

hth

> Please don’t write the class just help me sketch this out. My brain just is  
> not use to the whole OO thing 🙂

That takes a lot of the fun out of replying 😉
