19.11.2015 object oriented analysis & design & uml (unified modeling language)1 part vii:...
TRANSCRIPT
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 1
Part VII: Design Continuous
Interfaces and SubsystemsUse case Realization in Design
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 2
Content Interface
What is an Interface? Finding Interfaces Designing with Interfaces Advantages and disadvantages of interfaces Interfaces and Component-Based
Development Subsystems? Subsystems and Interfaces Physical Architecture and Layering Pattern
Use case Realization in Design
Chapter Roadmap
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 3
4
Introduction Designing a subsystem
is concerned with breaking a system up into subsystems (as independent as possible)
Interactions between subsystems are mediated by interfaces.
What is an Interface? Specifies a named set of operations Used to
Separate the specification of functionality form implementation of functionality
The interface provide The plugs and sockets To connect from outside
The interface defines A contract implemented by the classifier Classifier: packaged in a subsytem or component
Designing to implementation: Designing by connecting specific classes together Interface is realized by any number of classes An interface cannot be instantiated
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 5
Interface Content Interface contains operations Fully specified:
The attributes and operations of an interface should be fully specified, with:
Complete operation signature The semantics of the operation (text or pseudocode) Name and type of the attributes Any operation or attribute stereotypes, constraints, tagged values
Optional: A sterotype
Name, Parameters and their types Return type
Set of constraints Tagged values
The followings are not allowed in interfaces Operation implementations Relationships
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 6
UML Interface Notation
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 7
The set of interfaces realized by a classifier is known as provided interfaces,
Note that the two different notations for the realization relationship
8
Interfaces The set of interfaces
needed by a classifier for its operations are called required interfaces
Note that the two different notations for the dependency relationship, with the socket symbol in the right-hand side
9
Interfaces an example of an assembled system
10
Interfaces
Interfaces in Java: the collection classes
11
Interface realization vs. inheritance
Interface: “realizes contract specified by”
Inheritance: “is a” Both can generate
polymorphism Figure shows
an inheritance-based solution
12
Interface realization vs. inheritance
Adding non-borrowable items such as journal needs further modeling
13
Interface realization vs. inheritance
A more elegant solution is To add LibraryItem between
14
Interface realization vs. inheritance
Still better is to combine inheritance and
interfaces, Advantages:
every item in the Library is a LibraryItem;
borrowability concept factored out;
fewer classes; simpler inheritance hierrachy; fewer
compositions/inheritances
Interfaces and Time of Realization
Adding new devices via interface is very easy
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 15
Sensor
activate()deacti vate()
Zone
activate()deacti vate()...
Alarm
activate()deacti vate()
Activator
*
1
*
1
IdCard
activate()deacti vate()
Collection
List Set
SortedSet
Java Implements collection classesBy Java you can leave realization to implementation time!
Finding InterfacesConsider to implement using interfaces:
Challenge each of association If association needs flexibility
Challenge each message send Can the same message send to more than one type of classes
Factor out operation groups Might be reusable elsewhere Repeating in more than one class
Look the classes playing the same role Role may indicate a possible interface
Look for future expansion Interface makes easy for expansion!
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 16
Designing with Interfaces Design common protocols
realized by many classes or components Example:
A complex system with different communication protocols:
Use open() close() read() write()
Classes having reflexive associations are candidates for interfaces
Interfaces Provide the ability to plug things to the systems Extension is easy
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 17
Interfaces and Component-Based Development
To construct software from plug-in parts: One interface => multiple implementation Each implementation will
abide the same contract Replace the component easily
Coupling between the classes is reduced!
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 18
PrinterCustomer
Order
PrintManager
<<uses>><<uses>>
19
Advantages and disadvantages of interfaces
Designing with interfaces increases flexibility and extensibility a model can be neatly separated in cohesive subsystems
using interfaces supports low coupling by reducing the number of dependencies between classes, subsystems and components
Drawbacks of interfaces relate to added complexity and increased performance costs
As a guideline, use interfaces
for the more “fluid” parts of the system
and dispense them for the more stable parts of the system
20
Interfaces and component-based development
Interfaces are key elements for component-based development (CBD)
They allow addition of “plug-in” parts without changing the specification
Both with components and subsystems, interfaces support low coupling and provide high architectural flexibility
21
Components A component is
a modular part of the system encapsulates its contents manifestation is replaceable within its environment
It acts as a black box external behavior is completely defined by
its interfaces (provided and required);
hence, it can be replaced by any other component that supports the same protocol
22
Components Components may depend on other components To decouple components,
always mediate the dependency with interfaces
23
Component Stereotypes
24
Subsystems
A subsystem is a component acts as unit of decomposition for a larger system
Interfaces connect subsystems to create a system architecture
Subsystems are used to: Separate design concerns Represent large-grained
components Wrap legacy systems
25
Architecture and the layering pattern
Arrange subsytems and interfaces into layers that are semantically cohesive
Connect subsystems via interfaces Java packages are
just connected with dependencies!
26
Use case Realization in Design
Analysis Interaction Diagram
Add Course at Analysis27
Design Level Diagram
added the GUI layer, high-level operations are resolved
into specific methods of classes, complete with parameters
object construction is shown by an explicit constructor method invocation.
28
Subsystem interactions
Once physical architecture of subsystems and interfaces are designed
model use case realizations as interactions between subsystems rather than as interactions between
classes. Interactions between subsystems
provide a very useful high-level view of how the architecture realizes use cases
without going into the low-level details of individual object interactions.
29
Customer Subsystem with a single interface: CustomerManager
actor interacting with this subsystem. As the subsystem provides realizations
for all of its interfaces and operations we show the messages on the interaction diagram
going to the subsystem itself
30
20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 31
End of Chapter