Show Lecture.HelperClasses as a slide show.
CS253 Helper Classes
Helper Classes
- C programmers create helper functions
- C++ programers create helper classes
If your class has to do several things, then it may help
to break it down into smaller classes.
We didn’t evolve to do object-oriented programming. Our brains aren’t
designed to do this sort of thing. They’re not very good at it.
Therefore, keep each class simple & managable.
Example
Consider a container that is a hash table using filesystem storage.
It may be useful to create a smaller class that stores a single item in the
filesystem. Now, create a hash table class that stores the filesystem
objects.
You can debug each class separately, and each class does only
one thing. The filesystem class doesn’t know anything about hashing,
and the hash table class doesn’t know anything about filesystems.
Objections
“I can understand this class just fine.
Is it too complex for you ?”
- Gosh, aren’t you masculine. 🕱♂
- Making things deliberately more difficult,
just to prove that you can do it, is a fine attitude for weight-lifting,
but not for programming.
- Especially not for code which is likely
to be maintained by others, so … all code.
Objections
“Having two classes will increase overhead.”
- May I see your profiling data? Oh, you don’t have any?
Yeah, I thought so.
- Your intuition is a poor guide, here.
- Also, having separate classes will decrease program development
time and maintenance costs.
- Engineering delays are orders of magnitude more important
than a few microseconds of function call overhead.
Objections
“You expect me to write two classes!?”
- If you separate the functionality, then two classes are easier
to write than one overblown monster of a class.
- Do you make gigantic run-on paragraphs because the overhead of
actually starting a new sentence with the period and the capital
letter and the agony of deciding whether to type one space or two is
too much for you and therefore you “save time” by never breaking your
paragraph up into sentences which would not only help you as the
author break up your thoughts into manageable and orderly components
but also help the poor reader by making the input bite-sized and
flowing in an sensible fashion and therefore cost the reader a vast
amount of time by making them reread the same enormous paragraph
several times in a vain attempt to comprehend it while cursing the
writer to the flames of perdition?
Alternatives
If you’re afraid of writing classes, then look for a new profession.
There are so many!
👩🏭
🕵️♂️
👩🔬
👩⚖️
💂♂️
👩🔧
👩🏫
👷♂️
👨🍳
👨🔧
👨✈️
👩🌾
👨🚒
👨🌾
👩🍳
👩🎨
👩💼
👮♀️
👩🚀
👷♀️
👨🏫
👩🎤
🎅
👩✈️
👩🚒
👨🔬
👩⚕️
👨🚀
🕵️♀️
👨🎨
👮♂️
👨⚕️
👨🎤
👨🏭
👨💼
👨⚖️
💂♀️
🤶