19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design...

31
27.06.22 Object Oriented Analysis & Design & UML (Unified Modeling Language) 1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization in Design

Transcript of 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design...

Page 1: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 1

Part VII: Design Continuous

Interfaces and SubsystemsUse case Realization in Design

Page 2: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 3: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

Chapter Roadmap

20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 3

Page 4: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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.

Page 5: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 6: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 7: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 8: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 9: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

9

Interfaces an example of an assembled system

Page 10: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

10

Interfaces

Interfaces in Java: the collection classes

Page 11: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

11

Interface realization vs. inheritance

Interface: “realizes contract specified by”

Inheritance: “is a” Both can generate

polymorphism Figure shows

an inheritance-based solution

Page 12: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

12

Interface realization vs. inheritance

Adding non-borrowable items such as journal needs further modeling

Page 13: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

13

Interface realization vs. inheritance

A more elegant solution is To add LibraryItem between

Page 14: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 15: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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!

Page 16: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 17: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 18: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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>>

Page 19: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 20: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 21: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 22: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

22

Components Components may depend on other components To decouple components,

always mediate the dependency with interfaces

Page 23: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

23

Component Stereotypes

Page 24: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 25: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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!

Page 26: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

26

Use case Realization in Design

Page 27: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

Analysis Interaction Diagram

Add Course at Analysis27

Page 28: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 29: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 30: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

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

Page 31: 19.11.2015 Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VII: Design Continuous Interfaces and Subsystems Use case Realization.

20.04.23 Object Oriented Analysis & Design & UML (Unified Modeling Language) 31

End of Chapter