In this chapter you're going to design your own plugin. You'll add the
last necessary bits to your toolbox. You'll learn the following:
• How to assign responsibilities to classes
• How to translate responsibilities into functions
• How to do a little design, a little coding, and a little testing, all as
You'll be able to start working on your very own plugins.
Design Your Own Plugin
For all the plugins we've looked at so far, I've led the way and shown you what
to do. In this chapter I'll give you some suggestions and hints to help you
develop your own plugins from scratch. Together we'll go through the steps
for a brand-new plugin and see how it works.
We're going to (more or less) follow these steps:
Have an idea: I want a plugin to do _________.
Gather your materials.
Lay them out.
Try each part.
Knit it all together.
IMPORTANT NOTE: Even though I've laid out these steps in order, and we'll
go through them in order, the real world doesn't usually work that way.
Creativity and invention rarely take a direct, linear path from idea to execution.
Instead, you'll discover that something doesn't work the way you thought it
did. The code you wrote is all wrong. Or the code is perfectly right but not
what you need. That's all totally normal, and really it's what writing code is
You may need to throw out anything you've done and do it over, up to and
including the entire project. Hey, even the government does that with $100
billion projects, so we can do it too.
Professional programmers tackle this problem by taking very small steps: do
one small, bite-size thing at a time, make sure that works, then go on to the
next. Any time you realize that you've made a mistake or misunderstood
something, go back and fix it right then and there. Don't think you'll
remember to fix it later; you won't. Trust me on that one.