30
© Dennis Hart 2001 © Dennis Hart 2001 OOAD OOAD Packages, Dependencies & Packages, Dependencies & Interfaces Interfaces Dr Dennis Hart Dr Dennis Hart

1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

Embed Size (px)

Citation preview

Page 1: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

11© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Packages, Dependencies & Packages, Dependencies & InterfacesInterfaces

Dr Dennis HartDr Dennis Hart

Page 2: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

22© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

ComplexityComplexity

Many systems involve a significant level Many systems involve a significant level of analysis and design complexityof analysis and design complexity

Human capacity to manage complexity Human capacity to manage complexity is limitedis limited

Psychologists have found we can deal Psychologists have found we can deal with around 7 to10 items at once before with around 7 to10 items at once before starting to get overloaded and confusedstarting to get overloaded and confused

Page 3: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

33© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Systems & ComplexitySystems & Complexity

A very small system might have a class A very small system might have a class diagram with 7 to 10 items (classes)diagram with 7 to 10 items (classes)

A medium sized system might have 30 A medium sized system might have 30 to 100 classesto 100 classes

A large system might have many A large system might have many hundreds, or possibly over a thousand, hundreds, or possibly over a thousand, classesclasses

Page 4: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

44© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Packages & ComplexityPackages & Complexity

The UML concept for dealing with The UML concept for dealing with complexity is the complexity is the packagepackage

A package is a “grouping of model A package is a “grouping of model elements and diagrams”elements and diagrams”

A package can be viewed as a A package can be viewed as a subsystem – in fact in the UML a subsystem – in fact in the UML a “subsystem” is just a particular kind of “subsystem” is just a particular kind of packagepackage

Page 5: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

55© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

The Package SymbolThe Package Symbol

Package symbol (“folder”)Package symbol (“folder”)

Package creation toolPackage creation tool

Subsystem creation tool (subsystems are just Subsystem creation tool (subsystems are just specialized packages)specialized packages)

Page 6: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

66© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Package ExamplePackage Example

Suppose we needed to extend our Suppose we needed to extend our MPMS model to include other personnel MPMS model to include other personnel related matters like:related matters like:• Discipline & LegalDiscipline & Legal• RecruitingRecruiting• Honours & AwardsHonours & Awards• … … and so on …and so on …

Page 7: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

77© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Package ExamplePackage Example

We would wind up with a greatly We would wind up with a greatly expanded and much more complex expanded and much more complex model if we just added the necessary model if we just added the necessary use cases, classes, interaction use cases, classes, interaction diagrams, etc neededdiagrams, etc needed

Instead we can use packages to Instead we can use packages to organize the increased complexityorganize the increased complexity

Page 8: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

88© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Package ExamplePackage ExampleNew (empty) packagesNew (empty) packages

New package (empty) for our existing modelNew package (empty) for our existing model

Page 9: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

99© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Reorganizing the ModelReorganizing the Model

Now we need to move all the existing Now we need to move all the existing model elements (that concern model elements (that concern promotions & postings) into the promotions & postings) into the appropriate packageappropriate package

Select the elements to be moved (in the Select the elements to be moved (in the Explorer window) and then drag and Explorer window) and then drag and drop them onto the package icon drop them onto the package icon

Page 10: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1010© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Reorganizing the ModelReorganizing the Model

Drag & dropDrag & drop

Page 11: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1111© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Reorganizing the ModelReorganizing the Model

Model elements now in Model elements now in “Promotions & Postings” “Promotions & Postings” packagepackage

After minimzing After minimzing “Promotions & “Promotions & Postings” Postings” packagepackage

Page 12: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1212© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

““Discipline & Legal” Package Discipline & Legal” Package (Partial) Class Diagram(Partial) Class Diagram

Clearly we need Clearly we need “Member” on this “Member” on this diagram (Members diagram (Members are charged with are charged with offences), but it is in offences), but it is in a different packagea different package

Page 13: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1313© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

““Discipline & Legal” Package Discipline & Legal” Package (Partial) Class Diagram(Partial) Class Diagram

Drag and drop from Explorer window into class diagramDrag and drop from Explorer window into class diagram

Page 14: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1414© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Package Element VisibilityPackage Element Visibility

However, if an attempt is made to connect the However, if an attempt is made to connect the “Member” class to (say) the Offence class with an “Member” class to (say) the Offence class with an association then …association then …

Page 15: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1515© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Packages, Visibility & Packages, Visibility & DependencyDependency

The elements inside a package are not The elements inside a package are not generally visible outside the packagegenerally visible outside the package

If an element (e.g. a class) inside one If an element (e.g. a class) inside one package needs to “see” an element package needs to “see” an element inside another package then there is (or inside another package then there is (or should be) a should be) a dependencydependency between them between them

Page 16: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1616© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Packages, Visibility & Packages, Visibility & DependencyDependency

To establish the dependency, create a To establish the dependency, create a new class diagram for the MPMS new class diagram for the MPMS systemsystem

This diagram will show the two This diagram will show the two packages between which the packages between which the dependency existsdependency exists

Page 17: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1717© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Package DependencyPackage Dependency

Drag and drop the relevant packages from the Explorer window Drag and drop the relevant packages from the Explorer window into the new class diagraminto the new class diagram

Page 18: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1818© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Package DependencyPackage Dependency

… … and create the dependency between themand create the dependency between them

Dependency Dependency tooltool The dependent The dependent

packagepackage

The package depended uponThe package depended upon

The dependency linkThe dependency link

Page 19: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

1919© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Inter-Package AssociationsInter-Package AssociationsAssociations between classes in different packagesAssociations between classes in different packages

Note that the associations can only Note that the associations can only be created be created fromfrom the other class(es) the other class(es) toto “Member” (Why?) “Member” (Why?)

Page 20: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2020© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Inter-Package Class VisibilityInter-Package Class Visibility

Once a dependency has been created, Once a dependency has been created, which classes (in the package which classes (in the package depended upon) are visible and which depended upon) are visible and which aren’t?aren’t?

This is determined by the specified This is determined by the specified visibility of each classvisibility of each class

Page 21: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2121© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Inter-Package Class VisibilityInter-Package Class VisibilityVisible to dependent packagesVisible to dependent packages

Invisible to dependent Invisible to dependent packagespackages

Page 22: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2222© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Packages within PackagesPackages within Packages

Packages can contain other packages Packages can contain other packages (as, indeed, the MPMS package (as, indeed, the MPMS package contains the others “Promotions & contains the others “Promotions & Postings”, “Discipline & Legal”, etc)Postings”, “Discipline & Legal”, etc)

Nesting of packages to more than 2 or Nesting of packages to more than 2 or perhaps 3 levels is unusualperhaps 3 levels is unusual

Page 23: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2323© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Designing PackagesDesigning Packages

What principles govern what should be What principles govern what should be contained in a package?contained in a package?

The basic considerations are the same The basic considerations are the same as those that apply when assigning as those that apply when assigning responsibilities:responsibilities:• Low couplingLow coupling• High cohesionHigh cohesion

Page 24: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2424© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Designing PackagesDesigning Packages

Essentially, there should be:Essentially, there should be:• Minimal associations, interactions and Minimal associations, interactions and

other types of dependencies between the other types of dependencies between the elements in different packageselements in different packages

• High functional cohesion between the High functional cohesion between the elements within a particular package (e.g. elements within a particular package (e.g. it should be easy to give the package a it should be easy to give the package a meaningful name) …meaningful name) …

Page 25: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2525© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Designing PackagesDesigning Packages

……• Relatively few elements in one package Relatively few elements in one package

that need to be visible to and/or used by that need to be visible to and/or used by elements in other packageselements in other packages

Page 26: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2626© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

InterfacesInterfaces

Interfaces are used to model the edges Interfaces are used to model the edges or “seams” in a systemor “seams” in a system

An interface defines a service (i.e. a set An interface defines a service (i.e. a set of available operations) offered by a of available operations) offered by a model element – for example, a model element – for example, a packagepackage

Page 27: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2727© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

InterfacesInterfaces

An interface is an abstract class (i.e. An interface is an abstract class (i.e. cannot have any instantiated objects) cannot have any instantiated objects) that hasthat has• No attributesNo attributes• Abstract operationsAbstract operations

The operations are available to clients, The operations are available to clients, outside the element offering the outside the element offering the interface, to useinterface, to use

Page 28: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2828© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Realizing an InterfaceRealizing an Interface

Eventually, an element (e.g. a package) Eventually, an element (e.g. a package) offering an interface must offering an interface must realizerealize that that interfaceinterface

That is, one or more classes in the That is, one or more classes in the package must implement the operations package must implement the operations defined in the interfacedefined in the interface

Page 29: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

2929© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Interface SymbolInterface Symbol

aPackage uses (i.e. is dependent upon) the interface aPackage uses (i.e. is dependent upon) the interface operations offered or “realized” by bPackageoperations offered or “realized” by bPackage

DependencyDependency

InterfaceInterface

Page 30: 1 © Dennis Hart 2001 OOAD Packages, Dependencies & Interfaces Dr Dennis Hart

3030© Dennis Hart 2001© Dennis Hart 2001

OOADOOAD

Questions?Questions?

?Next