-
Notifications
You must be signed in to change notification settings - Fork 0
InitComponent
Some software requires initialization, e.g. a database must be opened, encryption key retrieved etc. Some software does not require any initialization process at all. That is not what we talk about.
We talk about allowing other developers to use your component. You have to provide a factory (Factory pattern is a good thing).
public class YourComponentFactory implements SharkComponentFactory {
@Override
public SharkComponent getComponent() {
YourComponent yourComponentInstance = …;
// do your initialization / creation
return yourComponentInstance;
}
}
Developers using a component need two things: A factory and component interface.
Code initializing your component could look likes this:
YourComponentFactory factory = YourComponentFactory();
YourComponent component = (YourComponent) factory.getComponent();
A factory object is used to produce an instance of your component object. Now, developers can call methods on your component (component.yourMethod1();
). Use this code skeleton to implement e.g. unit test. A real setup is explained in the set step.
Components use others. That is what they are made for. There is a chain (never a circle!) of dependencies in most software systems.
Lets assume a component ProviderComponent
. There is a corresponing factory (ProviderComponent
). It offers methods to others. It does not need to know its using components.
Lets assume another component DependingComponent
that uses methods of ProviderComponent
. Component developers are very aware of the providing component. This component is actually required to initialize an instance of DependingComponent
. This requirement can be set into software by defining a dependent factory.
System initialization could look like this.
// independent factory
SharkComponentFactory providerFactory = new ProviderComponentFactory();
// note: getComponent() has no parameters - never.
ProviderComponent provider = (ProviderComponent)providerFactory.getComponent();
// dependent factory needs instance of another component to be created.
SharkComponentFactory dependentFactory = new DependingComponentFactory(provider);
// factory has a reference on a provider component instance and
// can put it into component during creation.
DependingComponent dependentComponent = (DependingComponent)dependentFactory.getComponent();
Use this code skeleton to implement e.g. unit test. A real setup is explained in the set step. It is slighthly different.
SharkPKIComponentFactory can make use of others components but does not need to. In that case, a remote key store can be injected or it can choose its own.
We know how to initialize a component and even a chain of dependent components. Now, we can put them to work by bringing them into our ASAP system. Let's start our Shark application.
- What's a hub
- hub information management
- connection management