One area of interest worth expanding on is the method of data transfer. It should be realized that passing everything around as a String is not the best idea. After all, you'd have to spend time parsing data out. Java objects might be a nice compromise, except they tend to take up a lot of memory, and still have an associated Class type. XML is my new go-to-guy. Storing a Document in a database is like saying there's molecules in my house, they could be anything. Documents are nice and generic, and support OOP designs. They enable a single-typed database that actually stores a range of different object types. Our API relies heavily upon the mysterious, but generic XML Document. Processes know how to access their designated Documents, and only their designated Documents. Thus, processes are the only thing responsible for knowing how to handle the Document's internal format. This helps to promote encapsulation, extensibility and information hiding.
...And now,I humbly offer these low-hanging fruits of wisdom regarding API design:
1. Figure out what's important.
Will energy savings trump extensibility and elegance of design? Is simplicity the better part of valor? Odds are you'll have to take one aspect at the cost of another. Figure it out before you start. It'll save you a long afternoon of face-palming.
2. Make sure the design is at least as extensible as it needs to be.
We made concessions in our extensibility because there's only so many sensors that a house can have (plus were on a budget). But make sure its flexible enough to grow.
3. Trace transactions from end to end.
We scrapped several ideas only after coding them, and then realizing they didn't work. Make sure the functionality is there.
4. "When in doubt, leave it out"
What does it mean? Who knows. But if you can find an applicable context, apply it!
5. Don't tell them how you did it.
A wise man once told me (I saw it on a Google Video) that users should never know exactly how a method does what it does, or else they may come to rely on it's process rather than it's result. For example, if you tell users how a hash value is calculated, they may use the hash function else where. If you ever change the hash function, you break their code.
No comments:
Post a Comment