Skip to content

0016: Designing for fun and profits



Today I’ve got confirmation of scalability and easiness of extend of OLGAtherer structure – I’ve decided to change method:

public List<Book> GetAllBooks(string repoName)
            return new BookRepository(this.ConnectionString, reponame).GetAll();

so it should return not List of Books but new object called BookCollection. This change has been suggested by Andrzej during last meeting. He said that method that returns whole collection should returns not simply list but object that contain list of entities and additional information eg. date that the table was created and name of the table. This isn’t important right now, but it would bring some profits in the future – we shall see in the distant future how it will work.

Ok, so I’ve created new class named BookCollection with three fields only (and rest of necessary stuff: getters and constructor that takes three parameters) and changed method GetAllBooks to:

BookCollection GetAllBooks(string repoName);

As you could imagine, this results with number of errors. BookRepository.GetAll() returns List not BookCollection. What to do? We could possibly change BookCollection to inherit from List. But simplier change looks like this:

public BookCollection GetAllBooks(string repoName)
            BookCollection bColl = 
             new BookCollection(
                           new BookRepository(this.ConnectionString, repoName).GetAll(),
                           new TableDataRepository(this.ConnectionString).GetTableData(repoName).CreationDate,
            return bColl;            

As you can see, I’ve just added new class TableDataRepository. How? VERY SIMPLE:

1) I’ve just add new contract: ITableDataRepository : IRepository that contains one method signature: TableData GetTableData(string tableName);

2) I’ve add TableDataRepository that implements ITableDataRepository in the way that BookRepository implements IBookRepository – it’s very simple, as you could check in the real code – few lines in each method.

Is this all? Yes! What’s beautiful here, that I could do the same for every new collection that I will imagine in the future. For the TableData it took me maybe 3 minutes to write whole code! Last thing that I did was to create new part of the DB class: DB.TableData and put there code that will be useful in the future – adding
table information, reading it, and so on – 3 extra minutes were worth hours that might be wasted if the structure would be different – don’t you think? 🙂

That’s all for today – next time I’ll try to put here complete UML class diagram of OLGAtherer application. In the meantime I read about WPF design, but I think that this may be rather not ideal approach. Maybe I should design simple WinForm and continue coding “guts” of the application – after all, if the program will be good, I will easily find some WPF experts. If the program will be terrible, baeutiful interface won’t help.

Best regards,

Leave a Comment

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: