A typical Internet application usually begins with an architectural diagram. For example, a database connection component might be connected to a data cache, which is accessed by a search engine that is attached to some UI component. When you build an architectural plan, you typically follow several rules:
Use existing components where appropriate. If no component exists to do the job, try subclassing an existing component.
Break down large components into smaller components. Smaller components are easier to test, reuse, and inspect at runtime. This might result in a larger number of components, but Nucleus is designed to handle large numbers of components. Large monolithic components are sometimes difficult to spot, so always be on the lookout. It is generally good practice to design each component to perform a single function that can be described in a short paragraph.
Centralize functions that are shared by multiple components. For example, one component might spin off a thread that causes email to be sent every hour, while another component might spin off another thread that archives a log file each day. Both timing threads can be eliminated if the components take advantage of a centralized Scheduler component.
If a component is not completely self-contained—usually the result of following the previous point—be sure that its dependencies on other components are clearly enumerated. These dependencies are usually listed as properties of the component (see below). For example, a component might require a pointer to a Scheduler component and a
DatabaseConnection
component, so the component has properties of those types. A component should never need to know about its position in the grand scheme of the architecture—it only needs to know its most immediate dependencies.
When the architectural plan is complete, you can implement it with Nucleus and JavaBeans. If you design each component as a JavaBean, you can rely on Nucleus to create, initialize, and establish the relationship between Beans. You can build the components without regard for their initialization values or how their dependencies on other components are satisfied. These application-specific concerns are contained in configuration files that are read and interpreted by Nucleus.