Top Banner
1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University February 2011
36

1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

1

OOAD Detailed Design

From Design to Implementation

ITV Modelbased Analysis and Design of Embedded Software

Anders P. Ravn & Arne Skou

Aalborg University

February 2011

Page 2: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

2

Purpose

• Give meaning to UML diagrams

• Link design to programs

Diagrams:• Class Diagrams with associations and dependencies• State Diagrams with events and actions

Page 3: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

3

Basis from Design

• Architecture• Detailed Design for Model• Detailed Design for Functions• Detailed Design for Interface

We revisit the Architecture when we talk about Process Design

Page 4: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

4

Architecture: Simple Layered System

«component»Interface

«component»Functions

«component»Model

”Interface” knows ”Functions”, not the converse

”Interface” to Problem Domain

Problem Domain ”Data”

Application Domain ”functions”

Page 5: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

5

Simple Generic Architecture

«component» Interface

«component»Model

«component»UserInterface

«component»SystemInterface

«component» Platform

«component»OS

«component»FileSystem

«component»Function

...

Page 6: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

6

A variation: Layer access via aggregation

Page 7: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

7

A variation: Layer access via generalization

Page 8: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

8

Strategy PatternContext

State s

«abstract»Strategy

operation(State)

Function1

functions

* 1

Functionn

...

Page 9: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

9

Observer Pattern«abstract»

Subject

attach(Observer)

detach(Observer)

notify()

get(Object)

Model

State s

get(State)

«abstract»Observer

update()

ModelObserver

State observed

observers

1 *

subject

Page 10: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

10

Simple Generic Architecture

«component» Interface

«component»Model

«component»UserInterface

«component»SystemInterface

«component» Platform

«component»OS

«component»FileSystem

«component»Function

...

Page 11: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

11

Class implementation

class C {

public: char a;

public:

C(); // constructor

~C(); // destructor

}

Page 12: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

12

Auto implementation (c.h file)//## class c class c {

//// Constructors and destructors ////public : //## auto_generated c(); ~c();//// Additional operations ////public : //## auto_generated char getA() const; void setA(char p_a);//// Attributes ////protected : char a; //## attribute a };

Page 13: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

13

Auto implementation (c.cpp file)

#include "c.h"

//## class c

c::c() {

}

c::~c() {

}

void c::setA(char p_a) {

a = p_a;

}

char c::getA() const {

return a;

}

Page 14: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

14

Class method

Page 15: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

15

Auto implementation (c.h file)//## class c class c {

//// Constructors and destructors ////public : //## auto_generated c(); ~c();public : //## operation method(char) int method(char x);//// Additional operations ////public : //## auto_generated char getA() const; void setA(char p_a);//// Attributes ////protected : char a; //## attribute a };

Page 16: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

16

Auto implementation (c.cpp file)#include "c.h"

//## class c

c::c() {

}

c::~c() {

}

int c::method(char x) {

//#[ operation method(char)

a=x; return 2;

//#]

void c::setA(char p_a) {

a = p_a;

}

char c::getA() const {

return a;

}

Page 17: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

17

Class attributes public int getI() {

return i;

}

public void setI(int p_i) {

i = p_i;

}

//## class c public class c { protected int i; //## attribute i protected int j; //## attribute j protected int k; //## attribute k

protected int getJ() {

return j;

}

protected void setJ(int p_j) {

j = p_j;

}

private int getK() {

return k;

}

private void setK(int p_k) {

k = p_k;

}

Page 18: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

18

Class generalization

Class d{…}

Class c: public d{…}

Page 19: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

19

Class generalization by tool (c.h)

#include "d.h"

//## package Default

//---------------------// c.h //---------------------

//## class c class c : public d {…}

Page 20: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

20

Component (package)

namespace HelloPackage {

class upper{ ... };

Class display{ ... };

Class helper{ ... };

...

}

Page 21: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

21

Auto implementation// HelloPackage.hnamespace HelloPackage { class Display; class helper; class upper; }

// Display.h namespace HelloPackage { //## class Display class Display : public HelloPackage::upper {...} ...}

Page 22: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

22

Aggregation

////whole.h//// Relations and components ////protected : c* itsC; //## link itsC d* itsD; //## link itsD public : //## auto_generated void __setItsC(c* p_c); //## auto_generated void __setItsD(d* p_d);

/**************************************

////c.h//// Relations and components protected : whole* itsWhole; //## link itsWhole

whole::~whole() { cleanUpRelations();}

void whole::cleanUpRelations() { if(itsC != NULL) { whole* p_whole = itsC->getItsWhole(); if(p_whole != NULL) { itsC->__setItsWhole(NULL); } itsC = NULL; } if(itsD != NULL) { whole* p_whole = itsD->getItsWhole(); if(p_whole != NULL) { itsD->__setItsWhole(NULL); } itsD = NULL; }}

Page 23: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

23

Strong Aggregation

////whole.h//// Relations and components ////protected : c* itsC; //## link itsC d* itsD; //## link itsD public : //## auto_generated void __setItsC(c* p_c); //## auto_generated void __setItsD(d* p_d);

/**************************************

////c.h//// Relations and components protected : whole* itsWhole; //## link itsWhole

whole::whole(OMThread* p_thread) { setThread(p_thread, FALSE); initRelations();}void whole::initRelations() { itsC = newItsC(); itsD = newItsD();}void whole::cleanUpRelations() { { deleteItsD(); itsD = NULL; } { deleteItsC(); itsC = NULL; }}

Page 24: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

24

Dependency //// Relations and components //// layer.hprotected : Display* itsDisplay;//## link itsDisplay

////layer.cppvoid layer::setItsDisplay(Display* p_Display) { itsDisplay = p_Display;}

void layer::cleanUpRelations() { if(itsDisplay != NULL) { itsDisplay = NULL; }}

void layer::test() { //#[ operation test() j=itsDisplay->getI() ; //#]}

Page 25: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

25

Association

////c.h//// Relations and components protected : d* itsD; //## link itsD

// c.cpp //---------//## class c int c::method(int x) { //#[ operation method(int) i=x; return itsD->getJ(); //#]

Page 26: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

26

Association with *-multiplicity////c.h#include <oxf/omcollec.h>//// Relations and components protected : OMCollection<d*> itsD;//## link itsD

// c.cpp void c::_addItsD(d* p_d) { itsD.add(p_d);}

void c::addItsD(d* p_d) { if(p_d != NULL) { p_d->_addItsC(this); } _addItsD(p_d);}

Page 27: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

27

Simple State Machineint Display::rootState_dispatchEvent(short id) { int res = eventNotConsumed; switch (rootState_active) { case switchedOn: { if(IS_EVENT_TYPE_OF(off_system_id)) { rootState_subState = state_1; rootState_active = state_1; res = eventConsumed; } break; } default: break; } return res;}

void Display::initStatechart() { rootState_subState = OMNonState; rootState_active = OMNonState;}

Page 28: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

28

Two - State Machineint Display::rootState_dispatchEvent(short id) { int res = eventNotConsumed; switch (rootState_active) { case switchedOn: { if(IS_EVENT_TYPE_OF(react_system_id)) { //#[ transition 2 i++; //#] rootState_subState = Activated; rootState_active = Activated; res = eventConsumed; } else if(IS_EVENT_TYPE_OF(off_system_id)) { rootState_subState = state_1; rootState_active = state_1; res = eventConsumed; } break; } case Activated: {

Page 29: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

29

Hierarchical State Machinecase active: { if(IS_EVENT_TYPE_OF(suspT_system_id)) { Activated_subState = Tsuspend; rootState_active = Tsuspend; res = eventConsumed; } if(res == eventNotConsumed) { res = Activated_takeEvent(id); } break; }

int Display::Activated_takeEvent(short id) { int res = eventNotConsumed; if(IS_EVENT_TYPE_OF(susp_system_id)) { Activated_subState = OMNonState; switchedOn_subState = Psuspend; rootState_active = Psuspend; res = eventConsumed; } if(res == eventNotConsumed) { res = switchedOn_takeEvent(id); } return res;}

void Display::Activated_entDef() { switchedOn_subState = Activated; Activated_subState = active; rootState_active = active;}

Page 30: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

30

History State Machine case active: { res = active_takeEvent(id); break; }

int Display::active_takeEvent(short id) { int res = eventNotConsumed; if(IS_EVENT_TYPE_OF(suspT_system_id)) { Activated_subState = Tsuspend; rootState_active = Tsuspend; res = eventConsumed; } if(res == eventNotConsumed) { res = Activated_takeEvent(id); } return res;}

Page 31: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

31

History State Machineint Display::Activated_takeEvent(short id) { leaving activated if(IS_EVENT_TYPE_OF(susp_system_id)) { Activated_lastState = Activated_subState; switch (Activated_subState) { case active: { Activated_lastState = active; break; }………………Activated_subState = OMNonState; switchedOn_subState = Psuspend; rootState_active = Psuspend; res = eventConsumed; }----------------------------------------------------------------------------------------------------- case Psuspend: reentering activated { if(IS_EVENT_TYPE_OF(react_system_id)) {……………..Activated_subState = Activated_lastState; switch (Activated_subState) { case active: { Activated_subState = active; rootState_active = active; break; }

Page 32: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

32

System implementation of component HelloWorld

#include "MainHelloWorld.h"#include "c.h"#include "d.h"#include "whole.h"//----------------------------------------------------------------------------// MainHelloWorld.cpp //----------------------------------------------------------------------------//## configuration HelloWorld::HelloWorld int main(int argc, char* argv[]) { if(OXF::init(argc, argv, 6423)) { c * p_c; d * p_d; whole * p_whole; HelloWorld initializer_HelloWorld; p_c = new c; p_d = new d; p_whole = new whole; //#[ configuration HelloWorld::HelloWorld //#] OXF::start(); delete p_c; delete p_d; delete p_whole; return 0; } else { return 1; }}

Optional

Page 33: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

33

Overview of design implementationPurpose Realisation of the

component design

Concepts Patterns for component connection and UML diagram implementation

Principles •Evaluate component connections and change via patterns

•Generate code

•Keep consistency between design and implementation

Result A collection of component implementations

Toolsupport

is needed!

Page 34: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

34

Exercise

• Consider your ”Model” component

• Implement selected classes and associations/aggregations

Page 35: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

35

Auto implementation (d.h file)typedef struct d d;

/*## class d */

struct d { /*** User explicit entries ***/ char a; /*## attribute a */ };

/* Constructors and destructors:*/

/*## auto_generated */void d_Init(d* const me);void d_Cleanup(d* const me);d * d_Create();void d_Destroy(d* const me);

Page 36: 1 OOAD Detailed Design From Design to Implementation ITV Modelbased Analysis and Design of Embedded Software Anders P. Ravn & Arne Skou Aalborg University.

36

Auto implementation (d.c file)#include "d.h"

/*** Methods implementation ***/

d * d_Create() {

d* me = (d *) malloc(sizeof(d));

if(me!=NULL)

{

d_Init(me);

}

return me;

}

void d_Destroy(d* const me) {

if(me!=NULL)

{

d_Cleanup(me);

}

free(me);

}