Smart Box

About

Smart Box is a Component-Container framework. It allows users to create and run applications simply by loading pre-defined components into a container that hosts them.

There are four Component-Based Development roles:

·       Container Developer: This role builds the framework, which includes the container and the component base-class.

·       Component Developer: This role builds custom components extending the component base-class.

·       App Builder: This role uses Smart Box to add specific components to the container and connect them.

·       App Launcher: This role uses the application built by the App Builder.

Requirements

Smart Box provides a container and use cases that allow the App Builder to install components and the App Launcher to run them.

Container Use Cases

Example

Smart Box is a product of Company A (container developer). They sell it to Company B. B creates enterprise components for logistics, accounting, HR, and e-commerce (component developer). B resells the container and several components to Company C, which sells vacuum cleaners. The IT guy at Company C deploys the components into the container (App builder). A sales rep at C (the app launcher) uses the logistics component to arrange shipping of a vacuum cleaner to a customer.

Customization

To customize the framework a component developer defines the interfaces her components will require or implement, creates the implementations of these interfaces, then creates the classes that require these interfaces.

All classes must extend the Component class.

The class that launches the application must implement the App interface, which only requires a launching method called main.

In this example there are two components: A simple calculator component that implements the ICalculator interface, and a statistics calculator that depends on the ICalculator interface in order to implement its mean method:

 

This is how the above application would be expresses as a UML component diagram:

Adding Components

Next, the App Builder uses the Smart Box UI to add these components to the container:

When the Add Component button is pressed a File Dialog allows the user to locate and select components:

Launching Components

The App Launcher selects an App component, then launches it:

Here's the output produced:

Design

Here is the design followed by the Container Developer (i.e., you):

Notes:

·       The container contains a list of components. These components are indexed by the interfaces they require and by the interfaces they provide.

·       A component retains a reference to its container.

·       When a component is added to the container five things happen:

1.     It is added to the components list.

2.     Its container field is set.

3.     It is paired with its provided interfaces in the provided interfaces map.

4.     It is paired with its required interfaces in the required interfaces map.

5.     It is connected with components that need it or that it needs. (This is done by findProviders).

Here's the detail of the component design:

Notes

·       A component has a list of provided interfaces and a list of required interfaces. (Interfaces are represented by Java's Class<?> class.)

·       A component has a map that associates Fields with their types.

The container follows the Model-View-Controller design pattern:

Notes:

·       The container frame is the view. It provides a menu bar and a panel containing the add, remove, and launch buttons (see above).

·       Each menu (File, Help, and Container) has its own controller. The container controller also controls the buttons.

Implementation

·       The implementation heavily leans on Java Reflection.

·       Here's a sketch of the framework:

Container.java

Implementing the Component Selector Dialog (see above) was tricky. I stole the following code:

ComponentDialog.java

Project

1.     Implement the Smart Box framework by following the design given above.

2.     Implement the Stats Calculator described above using Smart Box.

3.     Implement a simple GUI for the Stats Calculator as a component.