Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminology: What's the difference between a class and a component?

Within the OO paradigm, we choose to use classes because they help us to break the system down, and provide nice side benefits such as encapsulation, separation of responsibilities, inheritance, modularity, etc.

If we look at a software system at the component level, can we simply treat components in the same conceptual way, i.e. a component is simply a "Big Class"? Or is there more to it than that?

What extra considerations must be given when designing components?

EDIT:

I know that a class and a component are different things. I also understand that a component may contain many many classes, each of which have their own roles and responsibilities.

I'll see if I can explain myself better.

  • Classes allow us to solve bigger problems because they allow us to think and design more abstractly.
  • There are rules & techniques to determine how to break down and assign data and functionality to classes.

This seems like a very similar situation to that of component design, just at a higher level of abstraction. Do the techniques used to determine what classes are needed scale up to components, and/or are there other things that affect a high-level system design that don't apply at the class abstraction level?

like image 407
andrewdotnich Avatar asked Aug 13 '09 07:08

andrewdotnich


2 Answers

what about using the project phase or role to differentiate them?

For example a component is a design-time unit (system architects, designers) whereas a class is an implementation-time unit (programmers). So designers speak about components (or subsystems or modules, the hight-level boxes in your architecture drawing) whereas programmer speak about components and classes (that implements components).

Under this view a component is implemented by one or more classes.

like image 56
dfa Avatar answered Nov 24 '22 19:11

dfa


I often think of Component in the UML sense (see Wikipedia description), whereby it represents a "modular part of a system". In this sense it tends to represent a larger piece of functionality than a class and could in fact be composed from multiple classes.

Considerations I would give to designing components are:

  • How it could be re-used. In particular what are the use cases that warrant implementing something as a component rather than bespoke code (As a grad I used to make everything re-useable!)
  • Providing sensible interface(s), and in some cases additional simplified interfaces, perhaps using the Facade pattern.

Hope that helps.

like image 20
Adamski Avatar answered Nov 24 '22 19:11

Adamski