/Molecule

Molecule is a Pharo component framework.

Primary LanguageSmalltalkMIT LicenseMIT

License Pharo 11 CI Pharo 12 CI

Molecule

Molecule Logo

Molecule is a component oriented framework for Pharo. His Component architecture approach provides an adapted structuration to User Interface (UI) or another software application which need Component features.

Molecule provides a way to describe a software application as a component group. Components communicate by use of services, parameters and event propagation. It is a Pharo implementation of the Lightweight Corba Component Model (Lightweight CCM). Molecule supports completely transparent class augmentation into component (not necessary to add code manually), based on Traits.

Documentation

Molecule documentation is available here: Molecule Documentation Home

The documentation includes some tutorials, pattern description and examples.

How to get Molecule

You can load the latest development version of Molecule or load a specific stable release with a tag, for example 1.2.10.

Continuous integration (CI) status badges show status of compatibility for all supported Pharo versions. You can use Molecule with your Pharo version when its badge is green !

Latest version

To install the latest version of Molecule in Pharo, you just need to execute the following script:

Metacello new
   baseline: 'Molecule';
   repository: 'github://OpenSmock/Molecule:main/src';
   load.

To add in your project BaselineOf:

spec baseline: 'Molecule' with: [ spec repository: 'github://OpenSmock/Molecule:main/src' ].

Specific release

To install a release in your Pharo image you just need to adapt and execute the following script. Don't forget to adapt the x.x.x tag to your wanted release in your script, for example 1.2.11.

Metacello new
   baseline: 'Molecule';
   repository: 'github://OpenSmock/Molecule:x.x.x';
   load.

To add in your project BaselineOf:

spec baseline: 'Molecule' with: [ spec repository: 'github://OpenSmock/Molecule:x.x.x' ].

Looking for an older Pharo ?

New releases of Molecule don't support old Pharo versions (< 10), but could work. Find below some Molecule branches for old Pharo versions.

Pharo 9 and 10 - last release is 1.2.8.

Pharo 8 - last release is 1.2.7.

Pharo 6 and 7 - last release is 1.1.1.

Prerequisites

Molecule Core has no dependencies.

Package 'Molecule-Benchmarks' requires SMark (https://github.com/smarr/SMark), this package contains benchmarks for working on performances.

Molecule developer menus

Molecule tries to offer a maximum number of Pharo user interface extensions to create and exploit components.

Library menu

A Molecule Component system can be monitored and inspected from the dedicated Molecule library menu. image

This menu also includes a special section for Debug and Tools, providing access to advanced features.

Contextual menus

There are mutiple accesses to Molecule features from contextual menus.

Packages contextual menu:

image

This menu provides metrics to have statistics on the Molecule code in selected packages. image

Classes contextual menu:

image

This menu provides actions and tools depending on the selected classes. With this menu you can force to define a Component, specially if you have deactivated the Molecule dynamic update or if you have a bug when a Component contract changed.

See Component implementations

contextual menu see component implementations
When right-clicking a Trait that uses the MolComponentType Trait, a new option appears in the Molecule sub-menu (as shown above):

see component implementations github
Clicking this option opens this window, showing all the Component implementations of a Type Trait.
The title of the window indicates the name of the Type Trait.
Clicking an implementation activates the Browse button, which is used to open it in the System Browser of Pharo (double-clicking also works).
Typing in the filtering list (above the two window buttons) filters the implementations' list.

See Component users

contextual menu see component users
When right-clicking a interface (that is, a Trait that uses the MolComponentEvents, MolComponentParameters or MolComponentServices Traits), a new option appears in the Molecule sub-menu (as shown above):

See component users github
The title of the window indicates the name of the Type Trait as well as the type of interfaces it is about (events, parameters or services).
In columns are shown the Type Trait requiring and offering this interface.
Clicking a Type Trait activates the Browse button, which is used to open it in the System Browser of Pharo (double-clicking also works).
Typing in a filtering list (below the columns) filters the relevant Type Traits' list.

Using Components

Start and stop method

Components can be used with the start & stop method.

To start a component:

component := MyComponentClass start.

To stop a component:

MyComponentClass stop.

Components can be identified with a name. To start a component with a specific name:

componentA := MyComponentClass start: #componentA.

To stop a component identified by a name:

MyComponentClass stop: #componentA.

Component life-cycle method

Components can be used with the life-cycle method, the two methods (start & stop, life-cycle) can be combined.

Starting a component is equivalent to:

MyComponentClass deploy.
component := MyComponentClass instantiate.
MyComponentClass activate.

With a name:

MyComponentClass deploy.
componentA := MyComponentClass instantiate: #compA.
MyComponentClass activate: #compA.

Stopping a component is equivalent to:

MyComponentClass passivate.
MyComponentClass remove.
MyComponentClass undeploy.

With a name:

MyComponentClass passivate: #compA.
MyComponentClass remove: #compA.
MyComponentClass undeploy.

Some examples

Examples are available in the package 'Molecule-Examples'. Open the Transcript before running examples, some results are showed in the Transcript window.

Clock System example

MolMyClockSystem startAlarmExample.

This system uses 4 components: a server time sends global hour to a clock. The clock sends local hour to alarms and to the final user (which could be an UI). The final user can change the parameters of the system as alarm time or set a manual time for the clock. The alarm is subscribed to the clock time, and sounds when it's time.

This system provides a global example of the use of components.

Geographical Position example

Examples are further detailed in the comment of MolGeoPosExampleLauncher.

1 - Start the demo: start a GPS equipment and a Map receiver (displaying result on Transcript)

MolGeoPosExampleLauncher start.

2 - Choose between available geographical position equipments:

Change the started component of MolGeoPosEquipmentType Type on the fly.

MolGeoPosExampleLauncher swapGPSInaccurate.
MolGeoPosExampleLauncher swapGSM.
MolGeoPosExampleLauncher swapGalileo.
MolGeoPosExampleLauncher swapWiFi.
MolGeoPosExampleLauncher swapGPS.

3 - To stop the demo:

MolGeoPosExampleLauncher stop.

To know more...

Publications related to Molecule:

Molecule: live prototyping with component-oriented programming

15 Years of Reuse Experience in Evolutionary Prototyping for the Defense Industry

Reuse in component-based prototyping: an industrial experience report from 15 years of reuse

Credits

License

This project is licensed under the MIT License - see the LICENSE file for details.