Working Hours Week

Work Week

Composing Projectors

We go from simple to more advanced user interfaces by combining previous work without touching (and possibly compromising) previous functionality. You cannot break what you do not touch.

The projector pattern encourages compositionality. The simpleWeekProjector delegates to the already existing simpleDayProjector, which in turn relies on the generic simpleFormProjector that again delegates to simpleInputProjector.

The visual appearance of an application needs to stay fresh and appealing. This is why it is so important that we can replace projectors very easily in the starter.

Visuals are ephemeral but logic is here to stay. This is why we never bind logic directly to the view but against the model. We allow the view (and how it binds to the model) to change frequently while keeping controller logic sustainable.

Composing Controllers

The business rules are the long-living core of the application. They are an investment. We invest in their test cases and their implementation. So, obviously, we want to build them properly without inconsistencies that would come from duplication. Controllers avoid duplication by composing more complex controllers from simpler ones.

For each day in the work week, the same business rules as in workday apply.

Since our weekController delegates all work to the already existing dayController, we can be sure to have the same business rules in place and that we enforce them correctly. We do not even have to test.

The dayController in turn delegates to the generic simpleInputController to ensure proper binding against the presentation model.

Testing

We only have to test those parts of the application that we add on top of the already existing projectors and controllers. This is another benefit of delegating most of the work to existing, well-tested code.

The simpleWeekProjectorTest simply asserts that the "total" views per day and week are available and updated on user input.

The weekControllerTest does the equivalent for proper calculation of the actual total number of minutes as exposed on the controller API.

Next Step

The "work week" has shown us how multiple inputs can coordinate to achieve a common goal.

The next step is to make this coordination even more elaborate with multi-way editing in a master-detail view.