Achievement #2

Last week I started looking at the flow of the system how it was then and how I wanted it to be. Plans are one thing, implementing the plan is another.

The initial dataflow:

Setup as of November 30. 2015

What I wanted to accomplish:

New setup draft after november 30 2015 setup

The problem with redesign is that there are always some parts of the system that is overlooked in the planning phase. For instance we are using a pattern called MVC, Model – View – Controller. Which means that the model is the data model. View is the user interface and the controller is the logic. What I wanted was to have the view, namely the editor, since that is the view, to be the part that updates the user. The controller would be in turn the one that has all the logic in it. The model would just be the data that the view and controller needs.

The editor as explained is the view, and that was very tightly knit with the controller, which is to be expected. What I had forgotten about when writing the data flow change was that the controller contains a lot of data that the back-end needs. I had 2 choices make everything in the achievement window an event, which means that some logic have to be implemented in the editor code or just fix the button clicks and rather have the editor fetch the data without events from the controller. Which is the solution I went for.

The other option is to create events for everything, but that would mean that every drop down menu, every selection and every choice would create an event and in my head that is not a good way to do it. The way I implemented the fix, the controller still does its magic and the button clicks just updates the background data and provides the information, so you keep the logic within the controller with the event calls.

The planned change was a success, in that the changes worked and seemingly seems to work a little bit faster. I got rid of 4 classes and implemented 1 new class. The one class handles events from the window and the other controllers in the system subscribes to the events based on the buttons they belong to. This makes it easier I believe to expand the system if we need to do that in the future. The data flow looked like this in the end:
actual flow

Not exactly as I had thought from the start, but close enough. The controller for the editor still has a connection with the other controllers, but it only gets the data and doesn’t modify or change it. The controllers themselves are in charge of organizing their own data.

The little box to the left was the deleted classes. The event system is the big box in the middle which triggers logic in the editor controller, as well as the three classes that the achievement system consists of. There is still a connection between the editors logic and the logic of the rest of the achievement system.

If I had been part of the project from the start and knew then what I now know, I think it would be better to see if you could make the classes more self containable, but right now I think the solution I came up with was nice. The system seems to respond better and we seem to have gotten control over the data flow. Now we know that a button click invokes the subscribing classes. The classes are updated and it is much easier to follow the flow of the program.

In the process I also got rid of 2 singletons. Earlier I thought that if you only needed one copy of a class you make it into a singleton. I have lately discovered that it is not the case. Even if you need it only once you create it when you need it and let the garbage collector fetch the trash once it is used. Which is a better solution. You don’t have to reset the variables every time you use it and it doesn’t take up space in memory. Sure the memory it consumes might not be much, but there’s no point in locking memory you don’t need used, especially when the tool is a back end tool and you don’t need to use it during run-time.

Next blog will most likely be about how to tab between fields in the editor. I have tried to get that working before, without success, but that was before I discovered why it didn’t work. Now I know why and I have an idea how to get it to work as it should.