Principles of Package Design

May 26, 2005 - Granularity: The principles of Package Cohesion. □ REP—The .... In Java. □ Counting import statements and qualified names. The meaning of ...
521KB Sizes 38 Downloads 143 Views
Principles of Package Design Chien-Tsun Chen Department of Computer Science and Information Engineering National Taipei University of Technology, Taipei 106, Taiwan [email protected] May 26 2005

OOD principles roadmap: What distinguish good and bad OO design? Single Responsibility Class

Separation of concern

Open-Closed

Inheritance

Program to an interface, not an implementation

Liskov Substitution

polymorphism

Favor object composition over class inheritance

Dependency-Inversion Interface-Segregation

basic

advanced

1

OOD principles and principles of package design Reuse-Release Equivalence

Single Responsibility Granularity Open-Closed

Common-Reuse Common-Closure

Liskov Substitution Acyclic-Dependencies Dependency-Inversion Interface-Segregation

class

Stability

Stable-Dependencies Stable-Abstractions

package

References

2

Outline „

Granularity: The principles of Package Cohesion … REP—The

Reuse-Release Equivalence Principle … CRP—Then Common-Reuse Principle … CCP—The Common-Closure Principle „

Stability: The Principles of Package Coupling … ADP—The

Acyclic-Dependencies Principle … SDP—The Stable-Dependencies Principle … SAP—The Stable-Abstractions Principle

What is Reuse-Release Equivalence Principle (REP)? „

Definition: the granule of reuse is the granule of release.

„

If a package contains software that should be reused, then it should not also contain software that is not designed for reuse. Either all of the classes in a package are reusable or non of them are.

3

What do you expect from the author of a class library that you are planning to reuse? „ „ „ „ „

Good documentation, Working code Well-specified interface, etc. And You want the author to maintain it for you. You want the author to notify you in advance of any changes he plans to make to the interface and functionality of the code, giving you the option to refuse to use any new versions.

This issue is primarily political and has a profound effect on the packaging structure of software „

„

To provide the guarantees that reusers need, authors must organize their software into reusable packages and then track those packages with release numbers Reusability comes only after there is a tracking system in place that offers the guarantees of notification, safety and support atha the potential reusers will need

4

We must also consider who the reuse is GUI library

Financial library

GUI library Financial library

What is Reuse-Release Equivalence Principle (REP)? „

Definition: the granule of reuse is the granule of release.

„

Either all of the classes in a package are reusable or non of them are.

5

Outline „

Granularity: The principles of Package Cohesion … REP—The

Reuse-Release Equivalence Principle … CRP—Then Common-Reuse Principle … CCP—The Common-Closure Principle „

Stability: The Principles of Package Coupling … ADP—The

Acyclic-Dependencies Principle … SDP—The Stable-Dependencies Principle … SAP—The Stable-Abstractions Principle

What is Common-Reuse Principle (CRP)? „

Definition: the classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all.

„

Classes that tend to be reused together belong in the same package.

6

Reusable classes collaborate with other classes that are part of the reusable abstraction

P3

P1

P2

P4

Software syste