1 © dennis hart 2001 ooad packages, dependencies & interfaces dr dennis hart
TRANSCRIPT
11© Dennis Hart 2001© Dennis Hart 2001
OOADOOAD
Packages, Dependencies & Packages, Dependencies & InterfacesInterfaces
Dr Dennis HartDr 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
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
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
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)
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 …
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
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
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
1010© Dennis Hart 2001© Dennis Hart 2001
OOADOOAD
Reorganizing the ModelReorganizing the Model
Drag & dropDrag & drop
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
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
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
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 …
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
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
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
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
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?)
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
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
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
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
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) …
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
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
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
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
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
3030© Dennis Hart 2001© Dennis Hart 2001
OOADOOAD
Questions?Questions?
?Next