Job Manager – Mind poored out into coding…

Back in 2006 I started a project called JobMan. It was inspired by GTT (Getting Things Done) methodology. Its primary purpose was to facilitate the quick creation of projects that could be broken further and further down into smaller and smaller tasks. As they say in GTT you cannot complete projects, only tasks related to the projects. I also wanted to be able to accurately log the amount of time spent on a project.

The initial UML drawings for the project are given below:

Start-An-Application-with-an-existing-file-that-exists
Start-Application-With-existing-file-that-is-not-found
Stop Watch UseCase
Word-Processor-Use-Case
Creating-A-Job
JobManager Class Diagram 1
JobManager Class diagram 2
JobManager Class Diagram 3
JobManager Use Case Diagram 1
JobManager Use Case Diagram 2

I intended to use other open source projects where possible and did so for a date picker and DB40 for an embedded database. Also at the time I was more intent on learning than creating something that would be used by someone other than myself. Hence, after the initial design, I coded and created features on a whim. I poured my mind out into my coding and tidied it up afterwards, usually when I found a bug.

The project was important in my development as it made me realise that projects need planning to avoid massive restructuring later. I learnt that design patterns could solve the problems I previously procrastinated over. Also my UI design needed work, which prompted me to buy ‘Filthy Rich Clients’ by Chet Haase and Romain Guy,although some of their work is now redundant given the slow rise of JavaFX2.

 

By 2009 I released  the project on sourceforge and then released its  current version in 2016 after spending quite some time using it in my current position. From this usage a number of bugs were fixed and the project optimised, e.g caching, listing subtasks by reference and not by objects.

 

Solid… Solid like a sock!

As continuation of the post Design Patterns and Good Practice post I will review and amend the Whitestarmedialibrary using the SOLID design principles.

Single Responsibility Principle

 

As it has been described to me the Single Responsibility Principle (SRP) is:

There should not be more than one reason for a class/method to change, or a class should always handle single functionality.

Also responsibilities should not be mixed into one class. The benefit being there is less coupling and therefore it is easier to change parts of the system without breaking something. Now do I understand this?  This may not be as silly a question as one might think. When I looked up SRP I found an article at https://www.toptal.com/software/single-responsibility-principle which discusses this directly from an MVC perspective. He argues the application logic is divorced from the controlling class. If I apply this to the WhitestarMediaLibrary the application structure could look like this:

This reduces the role of the WhitestarMediaLibrary to handing out various libraries and opening the initial database or databases. Do I want a situation where 2 or more libraries are interacting with the one database? Do I have a database for each media? Or do I restrict the library to manage one type of media at a time? This seems restrictive given someone may want to play music whilst they game or record TV whilst watching a film. I will delay this decision further down the line until I have applied the other SOLID principles.

However, I do need to move the database management to another class. This class shall be called WhitestarDBManager.

Open Closed Design Principle

 

Wikipedia states Open Closed Design Principle (OCDP) as “software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification” My first thought was that because this library is an uncompleted project this principle would not apply to the Whitestarmedialibrary. Only then, when the project is compiled and used in another project, would this principle apply.  However, if I declared WhitestarMedia as abstract it will allow for possible dependency inversion later and allow the possibility of new media types to be added later.

 

Liskov Substitution Principle(LSP) Principle

When looking for instances where I have overridden classes, I was unable to find anywhere I violated the super classes features. The only classes where I  could do this were  the WhitestarMedia class and its subclasses. However, the parent class in this instance was created to group common behaviour not as an interface for a subclass to implement.

 

Interface Segregation Principle

This has been stated in Jpassion course as:

 

“Clients should not be forced to implement interfaces they don’t us. Instead of one fat interface many small interfaces are preferred based on groups of methods, each one serving one sub module.”

 

At present there are no formal interfaces used. This however may change when I come to implement playlists.

 

Dependency Inversion Principle

Wikipedia describes this as:

 

  1. High-level modules should not depend on low-level modules. Both should depend on abstractions.
  2. Abstractions should not depend on details. Details should depend on abstractions.

 

As suggested above (in the OCDP section), changing WhitestarMedia to abstract changes the dependency between a library and its media to the abstract WhiteStarMedia and a specific media implementation e.g WhiteStarMedia_Music. However, could this also be applied to libraries themselves? In the above SRP section I moved the functionality of the database and the media management to specific classes. A WhiteStarMediaLibrary Interface could be created so new libraries can be added later. If the interface defined a constructor that required the type of media managed, the main whitestarMediaLibraryClass would could keep the various libraries in a collection instead of specific local variables. It would also allow multiple libraries of the same type to be added e.g. a library for online music service and one for a local service e.g. mp3 collection.  The resulting structure would look be:

This brings me back to another delayed decision, are databases to be single or multiple users? If I want a system where there can be multiple libraries managing media of the same type and some of these are streaming services such as Netflix or Spotify, then we would not be handing a database to them. A better option may be handing over a configuration file when initialising the library. This could be as simple as a properties file that is retrieved from local storage.  The file could be created and configured by the type specific library itself. This is then handed back to the WhitestarMediaLibrary when a close method is invoked. The DBmanager can  be moved to a utility library and then whether the library is shared or not is left to the implementation of the whitestarMediaLibraryInterface.  The resulting structure is reduced to:

All of the classes are then placed into packages e.g. Utility or WhitestarMediaTypes

Java Passion – Feeling the electricity? yes but only 12 volts of it…

In January I joined Jpassion.com. There were 2 reasons for this, one being I had previously used the service back in 2009 when it was run as JavaPassion.com. It was a Sun Microsystems sponsored service which suffered at the hands of the Oracles takeover. At that time I obtained 2 certificates in Javafx script and Java EE. I therefore knew the quality of the coursework was likely to be of a high standard.

The second reason was price. For a subscription of only $49 you get a clear set of courses you can complete. The current courses available are:

Each course is broken down into topics. For each of these there is a pdf presentation, a lab which includes a homework and a recording which is the pdf presentation and an audio track. The recordings are more than just a bland reading of the presentation. The speaker goes into each topic verbosely and other resources are referenced. All of the topics are set out well and I managed to bash through a number of these without a hitch.

You start to hit problems due to the age of some of the topics. The applets and Java web start are the  best examples of this. Very few projects use applets since they have been ripped out of most browsers (for very good reason). The Java web start was also a pain given that certificates are required to run them. You might say just add an exception. Unfortunately this does not work and though it is just about possible in windows, in Linux I just could not get it to work.

The OSGI topic also had versioning issues when using it in conjunction with the example maven projects. I ended up editing the manifest file in the jar to get OSGI to accept the example modules.

It would also be nice if there were some Java 9 and 10 courses that covered their new features, local var etc. Additionally the site design is a little tired.

It has to be emphasised that a year’s subscription is only $49 dollars and what you get is a wealth of knowledge here. Although it is little old in places, it is well worth a punt considering lots of people spend this on one night out or a week smoking.

Design Patterns & Good Practice

As part of refreshing my skills I have started a Jpassion.com course ‘Design Patterns’.

So I can practice what I am learning I decided to update an unfinished project titled WhitestarMediaLibrary (2009). It was originally for a DVR project as WINTV, at the time, was unreliable. This is not an issue since I moved to Linux and Mythtv does everything I want with the exception of the music library. The name Whitestar comes from the Babylon5 universe and all my media centre pc’s have carried the name, I am now on Whitestar9.

Anyway, this media manager is to have the following functions:

  • Manage 4 types of media; TV, Film, Music and Games
  • Pull metadata from the internet
  • Group classifications of genres. When I want to find Rock tracks I don’t want to search for every type of rock i.e soft metal, Hard Rock, thrash etc. I want to click on rock and it return all the tracks in that category.
  • Provide facilities such as playlist creation.

Below is a class diagram of the current implementation.

There are some classes missing here. In particular, extended Whitestarmedia classes for music and game that have been created with attributes specific to those types.

So to begin with,and for the next few posts, I will take this back to basics and review this project using SOLID principles (Single Responsibility Principle (SRP), Open Closed Design Principle,  Liskov Substitution Principle ,(LSP) Interface Segregation Principle, Dependency Inversion Principle).

Rest…When you don’t know where you are going any road will take you there.

I have taken some time to decide on where I should focus my energies. Learn a new language C++, C#, PHP? Given I have already invested a significant amount of time learning and creating programs in Java I have decided that, for now, I will stick with the Java eco system.

This leaves me with the next problem, what to focus on? The state of Java desktop is negligible, as far as I am aware it is not distributed now with  new PC’s.  The nightmare that was Java applets and how it has, rightfully, been kicked out of web browsers.  This leaves the realm of back-end server stuff.

The problem with this is I tend to learn by rote .I create programs I intend to use myself. So I need a trajectory which requires me to create something I could use or that someone else will use. i.e at my place of work. So the options I have thought of are:

  • I currently work in the NHS at a GP practice so I could create a comprehensive intranet site instead of the static one currently in place. Using a local PC as the server. For a practice of no more than 20 pcs the desktop machine should cope with the workload.
  • Create a service that allows me to access recordings, videos and music on a mythtv box from across the web.
  • Build the basic structure for a new clinical system.  The NHS currently uses EMIS Web (Egton) and System One (The Phoenix Project). Given the amount of frustration with the service provided by the current provider this is incredibly appealing and daunting in equal measure.
  • Do both the first and the second in this list.  Create a service that has a solid foundation for a practice intranet site. Then start to add facilities for patient documentation, management etc.

This last option is appealing as it would allow me the scope to create a replacement clinical system whilst knowing that, for the time being, its main purpose is to be a practice intranet site.  This leads me to my next choice, given it is a intranet site, it should lever the strengths of the web. i.e Rest.

I have had “REST in Practice: Hypermedia and Systems Architecture” by by Jim Webber , Savas Parastatidis and  Ian Robinson sitting on my shelf for a couple of years and, as I hate to waste anything, this is the way I am going to go.  In January I also signed up to Jpassion.com (see the upcoming post) which, although the site looks a little tired, it has some good content. It has a REST course.

So I will use both of these to start the MTMC intranet project (MTMC is the abreivation of the GP practice where I work).

It is now time to set sail, though all this floating about makes me sleep restlessly…