Guys, this is a tricky one:
I have two pieces of code I want to be able to mix and match, rather
than having to re-code them every time, spaghetti-wise.
One of them is a bubblesort-like iterator: think of a nested for
loop, with a few error-catching if-thens, and you've got it.
Now, what that's doing at the heart of it is checking a certain value
of an object, to see if it has a better value than the current max.
That's one piece of code. The other is simply the value and condition
(both) that is being checked. Do I want a minimum or a maximum? On
what field? That stuff.
Now, I can easily extract the for loop into its own procedure, and I
can have it call another procedure to check the condition. But I'd
have to somehow tell the for-loop procedure what new condition to
check every time I wanted to implement something new.
So, how do I pass an arbitrary condition (or procedure) into the for-
loop procedure? Or do I do something with object inheritence? Or do
I throw in the towel and make spaghetti code?
I want to get this right so I don't create problems for myself later
on in the project. I can imagine in a few months looking at this code
and wondering what the hell I was thinking... I'd rather just do it
neatly.
Conrad.