I commonly come across the terms "package" and "component" in software engineering. To my understanding, both indicates an independent software that can be used by another (larger) software.

What are the technical definitions of "package" and "component" and what are the difference between them?

有帮助吗?

解决方案

Component

The principle of systems made of components and the quest for reusable components have driven lots of work in the OO software engineering since the early 80s. There is therefore a rather clear consensus about what it is.

The SWEBOK provides the following definition in section 7.Software Design Strategies and Methods:

A software component is an independent unit, having well-defined interfaces and dependencies that can be composed and deployed independently.

The UML specifications provide for similar semantic in section 11.6.3:

A Component is a self-contained unit that encapsulates the state and behavior of a number of Classifiers. A Component specifies a formal contract of the services that it provides to its clients and those that it requires from other Components or services in the system in terms of its provided and required Interfaces. A Component is a substitutable unit that can be replaced at design time or run-time by a Component that offers equivalent functionality based on compatibility of its Interfaces.

The core idea of both definition is that the component is something that is self-contained ("independent ... having well-defined ... dependencies"), that provides an interface with a contract (i.e. a promised behavior, the latter being implied by "independently composable"), and is replaceable by another component offering the same interface and contract.

However, despite this consensus, component may still mean slightly different things to different people. For example, some consider that a component must be embodied in a deployable artefact (e.g. executable, dynamic library, ...), while other see the component already in the construction process (e.g. separate compilation unit).

Package

There is unfortunately lot less consensus on what a package is. The reason is that different mainstream technologies use the same term for different purpose. For example:

  • A java package is a mean to group related classes and interfaces, by organizing a common namespace. In practice, packages often end up (alone or with other packages) in JARs which are deployable artifacts that could match the definition of a component.
  • A Software deployment package is a group of files and configuration items that make a deployable software unit. Packages are in general versioned. Package managers allow to automate the deployment of such packages.
  • An UML package is a way to structure complex models into smaller, more manageable sub-models, by regrouping packageable elements.

So depending on the context, it is a group of deployagble artifacts that form a whole (which is in fact very close to the definition of a component), a group of components, or just a subdivision of something larger. The only general consensus here seems to be that a package regroups artifacts.

其他提示

Some years ago, I was participating at a workshop where the tutor asked us to list the terms for software "modules", "components", "libraries", "packages" and so on. The attendants came up with a list of, I guess, 20 to 30 different terms for this kind of thing, but not one clear definition.

So what I learned from this is, these terms are context dependent. When you talk to a group of Java developers, some of these terms have a specific meaning. If you are in an UML drawing session, the term "package" probably means just a rectangle in a diagram. If you are amongst a group of web admins or application admins, the semantics are also different again.

So first make it clear for yourself which specific context you have in mind, then you can probably find out (maybe by using Google, maybe by asking here), if terms like "package" or "component" have a clear definition in that context.

许可以下: CC-BY-SA归因
scroll top