The initial situation

In the software development regularly facing the situation that result values must be calculated from the given values. But what should happen when the result is queried again? Should the result be cached? Is it necessary to re-run the entire calculation? Must perhaps other components be informed about a change, for example, to update the display? What should happen if a value entered in one of many computations raises an error? The list of possible questions can be quickly quite extensive.
During my reflections on this subject five concrete requirements crystallized, which should be supported by the object model. I - not quite by accident - call these requirements as the "big calculation five". The component described here meeting these requirements was internally called "Business Calculation Foundation" and is now released under the product name CalculationWorks BCF.
CalculationWorks BCF (hereafter referred to as just BCF) is a collection of components and tools for the realization of complex recurring requirements in connection with the implementation of business logic. BCF is by me for various platforms of the.NET framework developed.

The "Big calculation five" - requirements and implementation in BCF

1. computed columns & properties, validation messages

The demand for computed columns/properties is clear and easy to understand. Calculated validation messages are an extension of this requirement.
Often, user input will be rejected if they are nonsensical or inconsistent. Nonsensical input, for example, the input of text in a date field, it is appropriate to dismiss this entry. In case of conflicting inputs, it is not always appropriate to reject the value at its input, the opposition became apparent. In an HR app is entered for an employee as year of birth in 1999 and then as year of employment 1988. It is not generally assume that the last entered value is incorrect. A message should appear on two fields or in an error list, which points out the contradiction and disappears when the user resolves the contradiction.
BCF offers the possibility to define a function object to a column and thus to make it a computed column. BCF tables can be added to validation objects, which are similar to the function objects. The results of the validation can be mapped to specific fields. Also maintains a list of all validation messages.
BCF function objects using their properties as parameters. By mapping the properties to columns, the BCF model provides the function object the appropriate parameters before calling calculation. The mapping can be a neighboring column in the same table as well as a column in another table. In the latter case, the path to the table in the form of linked relations name is specified simply. It is irrelevant whether or not the associated column of self is a computed column. In many cases, it is logical to keep a subtotal in a column and to reuse in several calculations. The profits in this approach usually exceed the costs, in terms of performance as well as in relation to the development and maintenance.

2. Relational model

An obvious requirement: As soon as the complexity of an object model, a simple list exceeds, it's advantage to use a relational model.
In a BCF object model multiple tables can be created and linked through relationships.

3. Undo / Redo

The frequently expressed demand for a way to undo user input or to be able to restore, is also frequently discussed away from the coding side or even ignored. The reason is that the subsequent implementation is complex and involves a high risk of error. Considering the requirement from the outset as a core element, the danger that the approach chosen proves to be inflexible and the implementation of other claims unduly difficult lurks.
BCF has implemented a solid undo / redo mechanism. Based on the compensation information of the transaction calculated columns and validation messages are considered, without that function objects are evaluated again.

4. Transactions

The popular example of money transfer from one account to another shows, that an action can include multiple data changes. These changes may only fully or not run (atomicity). Before and after each transaction the object model in a consistent state must be (consistency).

5. Change notification

Many components expect notifications about changes to work effectively. For example, to automatically update the user interface via data binding "Windows.Forms" and "WPF" is based on change notification. State changes should be published about events.
BCF provides change notification for all data changes - also for computed columns and validation results.

"Six, Seven, Eight" - other requirements

6. Extensibility

The usability for the developers is in focus developing BCF. The more a subject is important, the easier to be interchangeable, expandable and customizable.
For example: There are no restrictions on the types of the data. Programming your own functions and validators is possible without much effort. For many issues there are interchangeable helper classes. For example, write operations can intercept and redirect (similar to database triggers) or deposit your own functions to generate default values.

7. Performance

The widespread practice of immediately perform the necessary calculations upon data change, often leads to many unnecessary calculation calls. BCF manages data changes themselves and only performs the calculations at the end of the transaction. As a result, the unnecessary calculation operations are omitted. The performance is experiencing a significant increase depending on the complexity.
With data-bound calculated object models often 90 to 99 percent of the perceived time of processing is used for UI update. Therefore, event filters are implemented in the bindable BCF objects, suppressing redundant change notifications.
BCF has been optimized for use in applications and apps with user interface. This resulted in the following performance strategies:
• Allow higher memory consumption to reduce calculation time.
• Allow longer initialization time, to get faster response on data update.

8. Testability

Analog to the extensibility was considered in the development of BCF: ever more important a subject, the easier it testable supposed. For example, can be your own function classes directly instantiated, without generating an object model, supplied with parameters and executed.

BCF - an overview

BCF is composed of the BCF library and the editor of BCF. The BCF library contains the classes required to run sophisticated object and view models. The BCF Editor is the tool to create models and generating program code.

The Components

BCF includes the following elements:

BCF library

The library contains the necessary infrastructure to use object models at run time.

Applications with Windows.Forms UI should use this library. Thus, bindable wrapper objects (viewmodels) are specially designed for Windows.Forms databinding.

Applications with WPF UI should use this library. Thus, bindable wrapper objects (viewmodels) are specially designed for WPF databinding.

BCF Editor

The BCF Editor is a great relief in the development of BCF data models. The BCF editor can edit BCF data model files and generates program code, for example to initialize a data model. The editor supports the developer assigning function parameters to columns and much more.
The BCF Editor is the first application that has been created with BCF.

Use of BCF

With BCF you can:

  • create tabular and relational object models that are fast and reliable
  • easy to implement calculations of any complexity
  • easy to implement changes to the calculation logic
  • isolate the calculation and validation objects from the data model (to improve the test and reuse)
  • implement static and content-based data checks
  • process data changes transactional
  • implement Undo / Redo without requiring complex programming.

Conclusion

BCF saves time and increases efficiency in software development and maintenance. The more complex dependencies and calculations in an object model, the obvious advantages of using BCF. The optimal usage scenarios for BCF are applications and apps with user interface. The excellent performance and flexibility make BCF powerful in developing applications for the Microsoft .net Framework BCF.