Lesson 8 - Part and DK Reuse

The goal of UHR is greater software system productivity. Our main approach to achieving this is reuse. The two things that are reused the most are parts and DK.

A part can be a "compound part" represented by a container. Container reuse is where we expect to see the largest productivity gains. After all, containers are subsystems, and system reuse lies at the end of the spectrum of reuse. This spectrum starts at method reuse, moves up to object reuse, then up to fixed groups of objects reuse (frameworks, parts or mini subsystems) and ends up at unfixed groups of object reuse (systems assembled from lesser forms of reuse). For us the last one is containers..

In UHR containers are parts assembled with DK, not code. Thus container reuse is the same as DK and part reuse. Let's look at a simple example of this. We don't yet have much of a Part Inventory, so we will reuse previous lessons.

The container DK:

<partdk>
    <parts>
        <part>
            <name>HelloThere</name>
            <type>uhr.tutorial.system01.PartA</type>
            </part>
        <part>
            <name>Calculator</name>
            <type>uhr.tutorial.system03.PaymentPenaltyCalculator</type>
            <dk_url>jcresource://uhr.tutorial.system03.StartSystem/Calculator.dk</dk_url>
            </part>
        <part>
            <name>Subcontainer</name>
            <type>container</type>
            <dk_url>jcresource://uhr.tutorial.system05.StartSystem/_Container.dk</dk_url>
            </part>            
        </parts>
    <start_commands>
        <invocation>
            <part>HelloThere</part>
            <command>RunTest</command>
            </invocation>
        <invocation>
            <part>Calculator</part>
            <command>RunTest</command>
            </invocation>            
        <invocation>
            <part>Subcontainer</part>
            <command>Start</command>
            </invocation>
        </start_commands>        
    </partdk>

By now you're fluent in reading Container DK, right? :-) It has three parts:

1. The PartA part is reused from exercise 1.

2. The PaymentPenaltyCalculator part is reused from exercise 3. Note how with the "<dk_url>" line we specify where to get the dk for the part. This is an example of leaf part and leaf DK reuse.

3. We reuse the entire system from exercise 5 by simply treating it as a container part, which we give the arbitrary name "Subcontainer". Since a container is created purely by DK, all we have to do is point to the container DK with the "<dk_url>" line. In this case class uhr.tutorial.system05.StartSystem services only as a marker class. The main() in it is never used.

In the start commands we do three commands:

1. We RunTest on the part named HelloThere, resulting in the output "Hello World".

2. We RunTest on the part named Calculator, with the expected output.

3. We Start the Subcontainer part. This causes output as in exercise 5.

Just for a quick review, here's:

The marker and starter classl:

package uhr.tutorial.system06;
import uhr.core.cell.NodeCreator;
import uhr.core.structure.Container;

public class StartSystem {

public static void main(String args[]) {
String url = "classresource://uhr.tutorial.system06.StartSystem/_Container.dk";
new NodeCreator().createAndStartSystem(url);

// Argument are (boolean startAtRoot, boolean includeHidden)
System.out.println("\n" + rootContainer.listTree(true, false));
}

} // End class

Run the system by the usual "java uhr.tutorial.system06.StartSystem" and you get the output:

Hello World
Hello World 3 with DK
The dk = [InterestRatePerDay=.001, MinimumPenalty=5.00, GracePeriodDays=7]
Calculated penalty of 5.1 on payment of 100.0 that was 10 days late.
Hello World 5
The dk = [InterestRatePerDay=.001, MinimumPenalty=5.00, GracePeriodDays=7]
Calculated penalty of 5.1 on payment of 100.0 that was 10 days late.
All 2 notifications successful.

+Root
    HelloThere
    Calculator
    +Subcontainer
        TestRecorder(I)
        Calculator
        HelloThere

While not very useful, this system does show how parts and DK are easiily reused. Please note how we did all this with no code, except for the trivial marker and starter class.

Naturally you may be curious about what the full system tree looks like. If we make the usual modification to the StartSystem class:

    // Argument are (boolean startAtRoot, boolean includeHidden)
    System.out.println("\n" + rootContainer.listTree(true, true));

The system tree becomes:

+Root
    core.NodeCreator(I)
    core.ParamStore(I)
    core.PartDKHandler(I)
    core.Linker(I)
    core.ConnectionRegistry(I)
    core.Matchmaker
    core.Lifecycle
    core.CellDK
    core.PartRegistry
    core.MessageRouter
    HelloThere
    Calculator
    +Subcontainer
        core.Matchmaker
        core.Lifecycle
        core.CellDK
        core.PartRegistry
        core.MessageRouter
        TestRecorder(I)
        Calculator
        HelloThere

Note how each container has the same five core parts, and the root has the 5 inheritable core parts. The rest are the domain parts specified in the Container DK for the one or more containers that make up a UHR system assembled from parts.