|
Posted by mootmail-googlegroups on 08/16/06 13:27
Simon Dean wrote:
> Which way is right?
>
I thought of another bit of advise for working with classes.
If you want to design a really good class, don't start with the class.
I know that seems counter-intuitive, but stick with me, here. Start
with the code that will use the class. Pretend as if the class is
already implemented and just start calling functions which you would
'expect' to be there in order to do what you need to do. After your
main program has used the class, then go back and make the class behave
like the program expected.
A common flaw I have seen in other people's code is that their classes,
while they do work, aren't very intuitive or easy to use sometimes.
They were written as the programmer thought they should be, and then
the code using them was written to accomodate their shortcomings, often
by the same developer. Just as a writer often has trouble
proof-reading his own writing, it is sometimes hard to see the
usability problems in a class when you are the one who wrote it and
intimately know it's inner workings.
A class isn't just a lump of code. It is a tool which should be easy
to learn, intuitive to use, and focused in its functionality. To see
well designed classes in action, just look at the .NET framework.
Thousands upon thousands of classes which no one would ever hope to be
able to memorize, yet a developer can sit down and use pretty much any
one of them without looking at documentation first because they were
designed from a user's perspective, not the developer's.
[Back to original message]
|