What is the key difference between object and component? Can anyone provide examples in Java that how objects and components are related? If possible, please provide some examples whether what are objects and what are components.

4 Answers
4

This is over-simplification (and subjective as well ) and I have mentioned it for the sake of simplicity and understanding. A component may be composed of other component as well. But each component serves a very specific purpose (e.g. Engine, Door, Tyre). The objects on the other hand are at more granular level and serve as building blocks of larger components/systems.

A component is not something specific to a particular language, but rather a way of organizing and thinking about the runtime structures of a system so the people developing the system can understand how the system they are building promotes or inhibits specific properties. Therefore, the following are true statements:

an object is a component

some conceptual collection of objects is a component

even a collection of components is a component

How you partition the system into components is going to depend on what meaning you want to convey to your fellow developers and what properties you need your system to achieve. Components connect with one another at runtime -- e.g. one object instantiating another, a web client connecting to a web server, a subscriber registering on an event bus. If you're using an object oriented language like Java, all components will be made up of objects.

Other examples of components, these from Component-and-Connector architectural styles, include tiers (N-Tier style), filters (pipe-and-filter style), objects, and components. "Component" becomes a sort of catch-all in many architecture descriptions so it is better to be more specific when possible.