Sometimes you don't want behavior with your data

I have heard it said that objects are data combined with behavior, which as a snappy summary strikes me as pretty useful; something like it has certainly guided me in structuring my programs. (Although I am nowhere nearly as strongly object-oriented as is popular these days; I still have at least a foot in the procedural programming camp.)

It is also a sensible notion, in the abstract; since data by itself is useless, so you might as well bundle it together with the code that understands it and call them one thing. (You usually can't manipulate the data without understanding it, so you just put all of the code that understands the data into one place. Phrased this way, one may begin to see some exceptions.)

However, I've come to realize that sometimes this is wrong; sometimes you actively want data without behavior dragged along with it, so you want pure data, not objects. The obvious case is (data) persistence, where I think that you are significantly better off if you do not try to tightly bind data and behavior when you save and restore the data. Here the important thing is usually the data, and you do want to be able to get at it without the behavior intervening.

(I think that part of this is because the behavior may change over time in various ways without the data itself changing.)

(This is probably obvious to experienced OO people, but I learned programming in the pre-OO days so I am still sort of feeling my way through all of this.)

These are my WanderingThoughts
(About the blog)

GettingAround
Full index of entries
Recent comments

This is part of CSpace, and is written by ChrisSiebenmann.

* * *

Atom feeds are available; see the bottom of most pages.

This is a DWiki.
(Help)

Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web

Search:
Written on 19 April 2009.
(Previous | Next)

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sun Apr 19 00:27:57 2009
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.