Starmapper Site : DataModel

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Data Model in Starmapper

Version 3 of Starmapper brought a new cool thing: Starmapper is no longer tied to Stars!, that is it no longer talks of Planets, Players and so on. Now it talks of Nodes, Regions and Node Infos. These are all interfaces - Starmapper cares only about some data it expects to get from concrete implementations. Where necessary, interfaces are generified to provide some additional type safety for implementers of Data Model - every concrete implementation of an interface is supposed to work with types belonging to this Data Model, not with base interfaces - this allows for Data-Model-private additional methods and properties of these classes that can be used internally for whatever purpose (usually to calculate node value). See the default implementation in jezuch.utils.starmapper3.model.stars package for examples and some enlightenment, if you find that my explanations don't explain enything ;) Code speaks for itself the best!

So, Data Model consists of concrete implementations of interfaces in jezuch.utils.starmapper3.model package:

Some of the methods also return a plain old Iterables to simplify processing (and complicate error handling (yes, I've fallen into my own trap ;) )) instead of custom "readers" for model objects. The Data Model implementation knows best where to get the data and how to process it and return to Starmapper.

The Data Model has a concept of "session", which makes an instance of DataModel interface a stateful object (which, fortunately, doesn't have to be thread-safe). At the start of a session a Starmapper application passes a Config object, from which the Data Model can read additional configuration data (the default Stars! data model does this too, if you're curious). It is even allowed to modify the Config object, but then it is required to undo any modifications at the end of the session.

The DataModel interface has a startApplication method. This is a trick to make Data Models and Starmapper work with all this generic stuff. The trick is called "double dispatch" (although usually used for a bit different purposes) - the application knows nothing about concrete implementations in the Data Model, but the Model should know what it provides, so the application asks the DataModel instance to call back with proper types. That's what the Application interface is for, and its generified (with the usual declaration) start method. If you don't want to do it in your DataModel, you can extend AbstractDataModel, which does what's necessary (it's pretty straightforward and classifies as a boilerplate code).

There's also another convenience class: AbstractNodeInfo. It takes care of some basic tasks, like providing getters for standard properties (and providing storage for them), implementing equals (you still need to override it if you add your own properties, but calling super.equals() is not a bad idea) and defining an additional method shouldMergeWith which performs basic conflict detection for NodeInfos (conflict is when two NodeInfos describe the same Node in the same point in time).

There are 275 comments on this page. [Display comments]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
SourceForge.net Logo
Page was generated in 0.2641 seconds