Skip to content

0021: OLGAtherer.Model structure explained

08/12/2010

Hi again,

As usual I write after quite long pause. During this absence I made a really nice progress. Unfortunately, if I write a code or do something else that is connected with program, I have no time to describe it on this blog. So I can write code or write posts – not both at the same time. This is very unfortunate, because during writing OLGAtherer I learn so much, come across so many interesting obstacles that I would be very happy to have time to bring it to you. Now I have two (or maybe more, I think that I recall this later, during writing this post) interesting things and I think that I will split it into two (three, four?) separated posts, because they have rather different nature.

First one is an architecture feature that we worked out with Andrzej. Second one is technical problem with SQLite connection layer (I’ve just recalled another two or three :)).

So, shall we?

I opened Visual Studio a second ago, and I try to figure out what to describe as first – there is so many changes…
To date, I have written about 2721 lines of code (including braces) and 1312 lines of comments. When I wrote last post, code was much much shorter 🙂 I have added some new projects, split old ones and now there are (alphabetically):

  • OLGAtherer.Controller: I think that application may have a structure similar to this described by MVC pattern. Controller runs whole application (this will be probably executable file) – shows forms, computes something, etc. Controller knows about model (old OLGAtherer.Core) and view (all forms), and manage them.
  • OLGAtherer.Core.Tests: same like always. It was created by me to test only OLGAtherer.Core feautres, but now I don’t use this. Maybe in future I will write pack of tests to check application, but now I don’t have time (and later I probably won’t do this due to lack of time). In short: this is rather useless right now.
  • OLGAtherer.GUI.Forms: this project contains View part of MVC. That includes any form that will be shown to the user. For now there are 5 forms, including MainWindow (main application window), StartWindow (shown short after start of application, user can pick collection here), AddCollection and AddUser forms (pretty self-explanatory) and SplashScreen (for now it’s just a form with jpeg background).
    In the future I will add OLGAtherer.GUI.Wpf project with WPF forms and user will be able to pick which GUI suits him best, but for now there is only WinForms set of windows, for test purposes mainly. I’m thinking about changing name of this project to OLGAtherer.View.Forms.
  • OLGAtherer.Model: previously OLGAtherer.Core – new name suits better to MVC pattern. Now any can see structure of the program at first glance. This project contains program engine actually – here are placed structures responsible for exchanging data with database.
  • OLGAtherer.Utilities: any tool that will be used in the other projects will be placed here. Now this project contains configuration utils, enumerators, logger, text utilities and my newest tool – DbBuilder class that creates complete SQLite database and provides it with data.

Most of these projects are quite simple – View contains only forms and almost no program logic. Controller shows forms, listen events from them and does actions in response. However, I’m very proud of OLGAtherer.Model – this is project that I spent most of the time on, and I think that this is visible right now. I cannot recall how many times I changed whole structure of this project – probably 5 or 6 times at least, but now it’s so clear and nice that I think maybe 2 or 3 changes will be needed to mark it as completed (it’s a joke :)). In this post I’d like to describe structure of it.

This project contains 1700 lines of code and about dozen of class.
Main class is DBManager. It can create database and return instance of DB class.
DB class has methods to read data from CollectionData table (table that contains information about all collections placed in database) and any other tables (Books, Stamps, etc.).
Above methods return CollectionDataCollection and BookCollection classes that inherit from generic EntityCollection class. The EntityCollection contains four CRUD methods. It’s quite smart implemented – you have EntityCollection (Book or something else) that contains entities from the table, and you can do anything you want with it. Let’s say you want to add few books to BookCollection. You can call then Add method:

public virtual void Add(IEnumerable<T> elems)
        {
            this.repository.Add(elems);
            this.items.ToList().AddRange(elems);
            SendMessage();
        }

This is beautiful 🙂 The method simply adds books to the list of books in memory, adds books to database and raise event that informs listeners that collection has been changed. What is nice here that base EntityCollection contains repository and items members. Any new collection will inherit from this base class and in 99% no changes will be need. If there would be non-standard collection, it could just override one or more CRUD methods 🙂 Simple, clean, nice – I just hope that there is no mistake in my thinking and this structure REALLY IS nice 🙂 Anyway it works quite nice right now and this is most important.

Database structure is rather simple too. There is one main table – CollectionData that consists of four columns:

  • IdNo that is autoincremented integer field
  • CollectionType – text field indicating type of the collection
  • FriendlyCollectionName – it’s unique field – two collections couldn’t have the same name
  • CreationDate – date that collection has been created

For any new collection supported by OLGAtherer new table will be created. For example, Book collections entities will be placed in Books table. This one has about 20 columns and one of the column is CollectionIdNo. This field indicates collection that entity belongs to. For now, with my knowledge about databases, I think that this is rather good structure, if not, please tell me why.

OK, that’s it for now. I have no idea what to add. I encourage to get source code from SourceForge. All you need to do this is SVN client and this link:
svn co https://olgatherer.svn.sourceforge.net/svnroot/olgatherer olgatherer

Best regards,
Paweł

Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: