Describe how component reuse is based on object composition.
Reusability and Components in COM
As discussed in a previous lesson, software components integrate at the binary level. How can we write a software component and reuse it to build a composite software component?
Using a component, we can integrate and combine FindFile's functionality into FileManager at runtime. We write code in the
FileManager component to load, activate, and access the FindFile component. The actual integration between the FileManager and FindFile.
Notice in the image above that the client does not "see" FindFile.
The FileManager and FindFile components integrate at runtime.
Because components integrate at the binary level (that is, at runtime by executing code) and not at development time, components do not support C++-type inheritance (that is, we cannot inherit from a binary object). Instead, components support object composition. This means that component objects reuse other components to build larger composite components.
Furthermore, this composition of objects happens at runtime via a binary mechanism (that is, via running code).
A simple way to think about object composition is:
At time T0, a client invokes component FileManager.
At time T1, as part of its initialization sequence, FileManager activates the FindFile component. Consider this step to be a composition of both objects.
For example, FileManager = FileManager + FindFile
At time T2, after FileManager has completed its initialization sequence, the client can invoke functionality (via interface calls) in FileManager. From the client's perspective, FileManager implements a specific feature set via interfaces. The client is not aware that part of this functionality comes from the reuse of the FindFile component.
The following image illustrates this reuse scenario as the composition of object FileManager and FindFile.
Object composition can be multilevel. For example, the FindFile component can be a composition of components.
This would not be visible to FileManager. The following diagram illustrates FindFile being composed from two additional components: LocalFileFind and NetworkFindFile.