Dr. Dobb's Journal - July 2008 - (Page 36) Core Technology GRAPHS VERSUS OBJECTS Our Guidelines 1. If you want your information to span languages and operating systems, use graphs. There are plenty of technologies and techniques for passing information around: object request brokers, data marshaling, XML encoding. Graphs take it to another layer of accessibility because they aren’t encumbered by changes like schemas are and can extend relationships further than traditional relational models. Objects require custom code to integrate or introspection with getters and setters, which quickly gets complicated and cumbersome. 2. If your knowledge requirements will change significantly (expand, shrink, morph), use graphs. It is easy to argue that data in either objects or graphs will work, but the moment you introduce dynamics, objects become barriers. Developers are always forced to handle information updates where graphs and their triples can be changed outside the development environment without recompiles. 3. If the questions about your knowledge will be ad-hoc and dynamic, use graphs. Hard-coded queries are not well suited for change. In everyday business, the answers to questions beget new questions whose answers beget more questions. Graphs have little preconditions about information organization and easily adapt to new questions. In fact, the more perspectives you encode using graphs, the richer the data is, much like social tagging. Objects require preplanning and design time for long-term considerations. 4. If your knowledge is resource constrained, use objects. The amount of code to support the fixed object example was noticeably smaller compared to the graph code. Decoupling knowledge via graphs comes at a resource cost. As a trade-off, a solution may consider generating an object from a graph when performance requirements demand it. 5. If your knowledge is complex and multityped, use graphs. Complexity represents itself in different kinds of relationships, multiple inheritance, diverse set of restrictions, and logical associations (for example, unions, disjoints). Although possible in objects, the labyrinth of code quickly gets quite murky. Graphs are designed to handle complex knowledge and its many expressions. 6. If your knowledge needs to be fully decoupled from your programming, use graphs. There are many reasons that we’ve lightly touched on why decoupling the knowledge from the programming proves useful. Various techniques such as inference and integrity checks can run against the knowledge. It is also easier to change (both the programming and the knowledge). 7. If you are concerned about attribute-level security, use objects. Object-oriented languages provide access modifiers to data. For example, Java uses private, public, default, and protected concepts. Access modifiers permit the realization of information hiding and encapsulation functionality. Graphs could support security—developers could use a security ontology to verify visibility, use triples to store security metadata about other triples, or any other of a handful of ideas. If you are new to graph development and design, this is an area we recommend you avoid when starting out. —J.H. and M.F. We can now sell that rotten lemon that has sat in the refrigerator for so long: Resource lemonSale = m.createResource(defaultNS + "lemonSale"); m.add(lemonSale, RDF.type, m.getResource(defaultNS + "Transaction")); m.add(lemonSale, m.getProperty(defaultNS, "containsPerishableItem"), lemon); m.add(lemonSale, m.getProperty(defaultNS, "hasBuyer"), john); m.add(lemonSale, m.getProperty(defaultNS, "hasSeller"), seller); Now we can query for all perishable items sold (looking for all triples with property containsPerishableItem) or simply all items sold: String queryString = "PREFIX store: " // PREFIX store: <http:// // www.example.com/storeOntInference# "SELECT ?item " // SELECT ?item "WHERE { " // WHERE { " ?trans store:containsItem ?item ." ? // ?trans store:containsItem ?item . " } "; // } Several points should be clarified. Lemon’s rdf:type value is inconsequential here; it is only perishable because it is part of the containsPerishableItem relationship. It is important to note that graphs won’t return any compile-time or runtime errors, such as if I sell my gorilla suit online and incorrectly add it as part of a containsPerishableItem property. Our lemon instance automatically becomes an item involved in a transaction by using containsItem or any of its subproperties. This is the spirit of Web 2.0: Our store will forever sell items of all shapes and sizes, including those we never anticipated, always an agent of change. We can easily create new ways to query this knowledge to better understand and grow our business. Refactoring object code on a frequent basis to support such dynamic activity becomes burdensome. Realistically, we can never plan for all the different items our clients will buy and sell; graphs let us better deal with such uncertainty. Scalability, flexibility, and ease of integration are easily met using the graph paradigm, for the intelligence is in the data and not the code. Conclusion Now that you have a basic foundation of graphs, we hope you’ll join us in expanding on graph possibilities including graph design, powerful queries, inference, alignment between graphs, distributed graphs, mapping to web services, and much more. DDJ which returns: 36 Dr. Dobb’s Journal l www.ddj.com l July 2008 http://www.ddj.com
Table of Contents Feed for the Digital Edition of Dr. Dobb's Journal - July 2008 Dr. Dobb's Journal - July 2008 Contents Friday Night Fish Fry Alia Vox Developer Diaries Developer’s Notebook Engineers Without Borders Conversations Patricia Tries Event-Based Architectures Graphs Versus Objects Lock-Free Queues Dr. Dobb’s Architecture & Design World Java and the Nokia N10 Internet Tablet Effective Concurrency The Agile Edge Swaine’s Flames Dr. Dobb's Journal - July 2008 Dr. Dobb's Journal - July 2008 - (Page Belly1) Dr. Dobb's Journal - July 2008 - (Page Belly2) Dr. Dobb's Journal - July 2008 - Dr. Dobb's Journal - July 2008 (Page Cover1) Dr. Dobb's Journal - July 2008 - Dr. Dobb's Journal - July 2008 (Page Cover2) Dr. Dobb's Journal - July 2008 - Dr. Dobb's Journal - July 2008 (Page 1) Dr. Dobb's Journal - July 2008 - Contents (Page 2) Dr. Dobb's Journal - July 2008 - Contents (Page 3) Dr. Dobb's Journal - July 2008 - Friday Night Fish Fry (Page 4) Dr. Dobb's Journal - July 2008 - Friday Night Fish Fry (Page 5) Dr. Dobb's Journal - July 2008 - Friday Night Fish Fry (Page 6) Dr. Dobb's Journal - July 2008 - Friday Night Fish Fry (Page 7) Dr. Dobb's Journal - July 2008 - Alia Vox (Page 8) Dr. Dobb's Journal - July 2008 - Alia Vox (Page 9) Dr. Dobb's Journal - July 2008 - Developer Diaries (Page 10) Dr. Dobb's Journal - July 2008 - Developer Diaries (Page 11) Dr. Dobb's Journal - July 2008 - Developer’s Notebook (Page 12) Dr. Dobb's Journal - July 2008 - Developer’s Notebook (Page 13) Dr. Dobb's Journal - July 2008 - Engineers Without Borders (Page 14) Dr. Dobb's Journal - July 2008 - Engineers Without Borders (Page 15) Dr. Dobb's Journal - July 2008 - Engineers Without Borders (Page 16) Dr. Dobb's Journal - July 2008 - Engineers Without Borders (Page 17) Dr. Dobb's Journal - July 2008 - Conversations (Page 18) Dr. Dobb's Journal - July 2008 - Conversations (Page 19) Dr. Dobb's Journal - July 2008 - Patricia Tries (Page 20) Dr. Dobb's Journal - July 2008 - Patricia Tries (Page 21) Dr. Dobb's Journal - July 2008 - Event-Based Architectures (Page 22) Dr. Dobb's Journal - July 2008 - Event-Based Architectures (Page 23) Dr. Dobb's Journal - July 2008 - Event-Based Architectures (Page 24) Dr. Dobb's Journal - July 2008 - Event-Based Architectures (Page 25) Dr. Dobb's Journal - July 2008 - Event-Based Architectures (Page 26) Dr. Dobb's Journal - July 2008 - Event-Based Architectures (Page 27) Dr. Dobb's Journal - July 2008 - Event-Based Architectures (Page 28) Dr. Dobb's Journal - July 2008 - Event-Based Architectures (Page 29) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 30) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 31) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 32) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 33) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 34) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 35) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 36) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 37) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 38) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 39) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 40) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 41) Dr. Dobb's Journal - July 2008 - Graphs Versus Objects (Page 42) Dr. Dobb's Journal - July 2008 - Lock-Free Queues (Page 43) Dr. Dobb's Journal - July 2008 - Lock-Free Queues (Page 44) Dr. Dobb's Journal - July 2008 - Lock-Free Queues (Page 45) Dr. Dobb's Journal - July 2008 - Lock-Free Queues (Page 46) Dr. Dobb's Journal - July 2008 - Lock-Free Queues (Page 47) Dr. Dobb's Journal - July 2008 - Dr. Dobb’s Architecture & Design World (Page 48) Dr. Dobb's Journal - July 2008 - Dr. Dobb’s Architecture & Design World (Page 49) Dr. Dobb's Journal - July 2008 - Java and the Nokia N10 Internet Tablet (Page 50) Dr. Dobb's Journal - July 2008 - Java and the Nokia N10 Internet Tablet (Page 51) Dr. Dobb's Journal - July 2008 - Java and the Nokia N10 Internet Tablet (Page 52) Dr. Dobb's Journal - July 2008 - Java and the Nokia N10 Internet Tablet (Page 53) Dr. Dobb's Journal - July 2008 - Java and the Nokia N10 Internet Tablet (Page 54) Dr. Dobb's Journal - July 2008 - Java and the Nokia N10 Internet Tablet (Page 55) Dr. Dobb's Journal - July 2008 - Java and the Nokia N10 Internet Tablet (Page 56) Dr. Dobb's Journal - July 2008 - Effective Concurrency (Page 57) Dr. Dobb's Journal - July 2008 - Effective Concurrency (Page 58) Dr. Dobb's Journal - July 2008 - Effective Concurrency (Page 59) Dr. Dobb's Journal - July 2008 - The Agile Edge (Page 60) Dr. Dobb's Journal - July 2008 - The Agile Edge (Page 61) Dr. Dobb's Journal - July 2008 - The Agile Edge (Page 62) Dr. Dobb's Journal - July 2008 - The Agile Edge (Page 63) Dr. Dobb's Journal - July 2008 - Swaine’s Flames (Page 64) Dr. Dobb's Journal - July 2008 - Swaine’s Flames (Page Cover3) Dr. Dobb's Journal - July 2008 - Swaine’s Flames (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.