Re: To Reference or not to reference



On 3/29/07, Marilyn Sander <marilyn-sander@xxxxxxxxxxxxx> wrote:
Chas,

You mention an issue that i've been pondering for a while. When and
why should you
use an OO style instead of a hash? If your basic data structure (or
several) is a hash,
what is to be gained by refactoring as OO? Isn't OO just a large
amount of syntactic
sugar surrounding some simple data constructs?

I'm not being facetious or sarcastic. I characterize OO as "syntactic
sugar" only as a
straw man to knock down. I really would like to know what people see as
the advantage to OO in this situation.
snip

When you have one data structure that has lots of functions called to
operate upon it you have an object whether you are doing OO style or
not. There are definite benefits of switching to an explicit OO style
in those cases:

1. The relationship of the functions to the data is clearer
2. You can generalize code up into super classes
3. Passing around objects is conceptually easier than passing around
hashes or hashrefs
4. You gain the ability to easily hide implementation and therefore
the ability to create facades (very useful for testing)

There are other benefits as well, but I need more caffeine.
.



Relevant Pages

  • RE: Who changed /proc/<pid>/ in 2.6.0-test5-bk9?
    ... when I pass an abstraction (data structure etc) around ... didn't have the ability to do CLONE_THREAD at all. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: I am needing a gentle introduction to accessing a perl array from a reference
    ... The data structure here is nothing more than a flat array. ... There is no hash anywhere in your code up at the top... ... Returns a list consisting of all the keys of the named hash. ... We need an understanding of the data structure if we are ...
    (comp.lang.perl.misc)
  • Re: Hash order bug?
    ... a review of one's Data Structures course may be in order ... did I realize that the underlying data structure is a hash, ... If you need to iterate through a hash in order by key, ...
    (comp.lang.ruby)
  • Re: use SDBM_File - Cant use string as a HASH ref
    ... I'm trying to tie this kind of hash into SDBM ... DBM files can only store simple values like strings and numbers. ... serialize the data structure as a string before storing it in the DBM, ... there were 100 perfect squares ...
    (perl.beginners)
  • Re: Parsing dhcpd.leases and squid access.log
    ... Paul Kraus wrote: ... Need to create a hash like data structure that contains the key as ... The dhcpd leases file contains all leases handed out and the ... - You never read from the %users hash. ...
    (perl.beginners)