開発環境
- OS X Yosemite - Apple (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- LLVM/Clang (コンパイラ, Xcode - Apple)
Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&D (Brett McLaughlin (著)、 Gary Pollice (著)、 David West (著) 、 O'Reilly Media)のChapter 5. Good Design = Flexible Software: Give Your Software a 30-minute Workout、INVENTORY ROUNDUP(No. 3337)をC言語で考えてみる。
INVENTORY ROUNDUP(No. 3337)
コード(BBEdit, Emacs)
find_instrument.c
#include "dict.h"
#include "instrument_spec.h"
#include "inventory.h"
static void initialize_inventory(inventory *in) {
/* ... */
properties = dictionary_new();
dictionary_add(properties, "instrument_type", "guitar");
dictionary_add(properties, "builder", "martin");
dictionary_add(properties, "model", "D");
dictionary_add(properties, "type", "acoustic");
dictionary_add(properties, "num_strings", 6);
dictionary_add(properties, "top_wood", "adirondack");
dictionary_add(properties, "back_wood", "mahogany");
spec = instrument_spec_new();
spec->properties = *(dictionary_copy(properties));
dictionary_free(properties);
in->add_instrument("122784", 5495.95, spec);
instrument_spec_free(spec);
properties = dictionary_new();
dictionary_add(properties, "instrument_type", "guitar");
dictionary_add(properties, "builder", "fender");
dictionary_add(properties, "model", "stratocastor");
dictionary_add(properties, "type", "electric");
dictionary_add(properties, "num_strings", 6);
dictionary_add(properties, "top_wood", "alder");
dictionary_add(properties, "back_wood", "alder");
spec = instrument_spec_new();
spec->properties = *(dictionary_copy(properties));
dictionary_free(properties);
in->add_instrument("V95693", 1499.95, spec);
instrument_spec_free(spec);
properties = dictionary_new();
dictionary_add(properties, "instrument_type", "guitar");
dictionary_add(properties, "builder", "fender");
dictionary_add(properties, "model", "stratocastor");
dictionary_add(properties, "type", "electric");
dictionary_add(properties, "num_strings", 6);
dictionary_add(properties, "top_wood", "alder");
dictionary_add(properties, "back_wood", "alder");
spec = instrument_spec_new();
spec->properties = *(dictionary_copy(properties));
dictionary_free(properties);
in->add_instrument("V9512", 1549.95, spec);
instrument_spec_free(spec);
properties = dictionary_new();
dictionary_add(properties, "instrument_type", "guitar");
dictionary_add(properties, "builder", "gibson");
dictionary_add(properties, "model", "5G");
dictionary_add(properties, "type", "electric");
dictionary_add(properties, "num_strings", 6);
dictionary_add(properties, "top_wood", "mahogany");
dictionary_add(properties, "back_wood", "mahogany");
spec = instrument_spec_new();
spec->properties = *(dictionary_copy(properties));
dictionary_free(properties);
in->add_instrument("82765501", 1890.95, spec);
instrument_spec_free(spec);
properties = dictionary_new();
dictionary_add(properties, "instrument_type", "guitar");
dictionary_add(properties, "builder", "gibson");
dictionary_add(properties, "model", "Les Paul");
dictionary_add(properties, "type", "electric");
dictionary_add(properties, "num_strings", 6);
dictionary_add(properties, "top_wood", "maple");
dictionary_add(properties, "back_wood", "maple");
spec = instrument_spec_new();
spec->properties = *(dictionary_copy(properties));
dictionary_free(properties);
in->add_instrument("70108276", 52295.95, spec);
instrument_spec_free(spec);
properties = dictionary_new();
dictionary_add(properties, "instrument_type", "mandolin");
dictionary_add(properties, "builder", "gibson");
dictionary_add(properties, "model", "F5-G");
dictionary_add(properties, "type", "acoustic");
dictionary_add(properties, "top_wood", "maple");
dictionary_add(properties, "back_wood", "maple");
spec = instrument_spec_new();
spec->properties = *(dictionary_copy(properties));
dictionary_free(properties);
in->add_instrument("9019920", 5495.99, spec);
instrument_spec_free(spec);
properties = dictionary_new();
dictionary_add(properties, "instrument_type", "banjo");
dictionary_add(properties, "builder", "gibson");
dictionary_add(properties, "model", "RB-3");
dictionary_add(properties, "type", "acoustic");
dictionary_add(properties, "num_strings", 5);
dictionary_add(properties, "back_wood", "maple");
spec = instrument_spec_new();
spec->properties = *(dictionary_copy(properties));
dictionary_free(properties);
in->add_instrument("8900231", 2945.95, spec);
instrument_spec_free(spec);
}
int main() {
inventory *i = inventory_new();
initialize_inventory(i);
dict *properties = dictionary_new();
/* */
dictionary_free(properties);
inventory_free(i);
}
0 コメント:
コメントを投稿