View
218
Download
0
Category
Preview:
Citation preview
Technology for a better society 1
Modeling I
Class modeling – the MAGIC with UML
Ketil StølenBased on slides prepared by Prof. Øystein Haugen, HiØ & SINTEF
Technology for a better society
Overview of lecture
Modeling– What is it?– Why do we do it?– Modeling and Programming – sides of the same coin?
The History LessonTooling
– Papyrus
The MAGIC of UML– Class modeling
2
Technology for a better society
• In which corner does threat belong?
• What would you put in the two other corners?
5
Exercise: Explain threat in the setting of the previous slide
Technology for a better society
• In which corner does risk‐value belong?
• What would you put in the two other corners?
6
Exercise: Do the same for risk‐value
Technology for a better society
Sustainable Knowledge of Informatics
7
Models Frameworks Patterns Algorithms
DSLGPL Formal Visual ....Programming
CompilersEditors Simulators Apps ....Verifiers
Technology for a better society
Modeling a system
A system is a part of the world– which we choose to regard as a whole, separated from the rest of the world during some
period of consideration, a whole which we choose to consider as containing a collection of components, each characterized by a selected set of associated data items and patterns, and by actions which may involve itself and other components
Mental systems– Systems existing in the human mind, physically materialized as states of the cells of our
brains
Mental and manifest models– when a limited set of properties is selected from a system
These definitions are from K. Nygaard and his DELTA team (in 1977)
8
Technology for a better society
A history of modeling languages
10
FORTRANAlgol Pascal
CNorwegian Computing Center
SIMULA(Nygaard, Dahl)
Xerox PARCSmallTalk (Kay)
AppleMacIntosh
OOA(Yourdon)
Objectory(Jacobsson) Booch
OMT (Rumbaugh)
UML 1.x (Rational/OMG)
SDL-88
MicrosoftWindows
Hoare-logic
CSPHoare Jones
VDMMilnerCCS
LOTOS (ISO)
COBOL
SQL
ER-model
SDL-92 (ITU)
Bell LabsC++
Sun
OODB
JAVA
Broy/StølenFocus
Corba
UML 2.0 (OMG)
SDL-2000 (ITU)
MSC-2000 (ITU) EJB Web services
MSC-92 (ITU)ROOM
(Objectime)
Technology for a better society
Focusing on Languages
11
FORTRANAlgol Pascal
CNorwegian Computing Center
SIMULA(Nygaard, Dahl)
Xerox PARCSmallTalk (Kay)
AppleMacIntosh
OOA(Yourdon)
Objectory(Jacobsson) Booch
OMT (Rumbaugh)
UML 1.x (Rational/OMG)
SDL-88
MicrosoftWindows
Hoare-logic
CSPHoare Jones
VDMMilnerCCS
LOTOS (ISO)
COBOL
SQL
ER-model
SDL-92 (ITU)
Bell LabsC++
Sun
OODB
JAVA
Broy/StølenFocus
Corba
UML 2.0 (OMG)
SDL-2000 (ITU)
MSC-2000 (ITU) EJB Web services
MSC-92 (ITU)ROOM
(Objectime)
Conceptual base of OO:Classes with Inheritance,Polymorphism (virtual),Co-routinesGarbage Collection
Technology for a better society
Making OO Popular and Commercial
12
FORTRANAlgol Pascal
CNorwegian Computing Center
SIMULA(Nygaard, Dahl)
Xerox PARCSmallTalk (Kay)
AppleMacIntosh
OOA(Yourdon)
Objectory(Jacobsson) Booch
OMT (Rumbaugh)
UML 1.x (Rational/OMG)
SDL-88
MicrosoftWindows
Hoare-logic
CSPHoare Jones
VDMMilnerCCS
LOTOS (ISO)
COBOL
SQL
ER-model
SDL-92 (ITU)
Bell LabsC++
Sun
OODB
JAVA
Broy/StølenFocus
Corba
UML 2.0 (OMG)
SDL-2000 (ITU)
MSC-2000 (ITU) EJB Web services
MSC-92 (ITU)ROOM
(Objectime)
Experimental programming:Runtime checksGraphical in/out
Effective programming andEfficient programs:Explicit memory control
Technology for a better society
The Three Amigos
13
FORTRANAlgol Pascal
CNorwegian Computing Center
SIMULA(Nygaard, Dahl)
Xerox PARCSmallTalk (Kay)
AppleMacIntosh
OOA(Yourdon)
Objectory(Jacobsson) Booch
OMT (Rumbaugh)
UML 1.x (Rational/OMG)
SDL-88
MicrosoftWindows
Hoare-logic
CSPHoare Jones
VDMMilnerCCS
LOTOS (ISO)
COBOL
SQL
ER-model
SDL-92 (ITU)
Bell LabsC++
Sun
OODB
JAVA
Broy/StølenFocus
Corba
UML 2.0 (OMG)
SDL-2000 (ITU)
MSC-2000 (ITU) EJB Web services
MSC-92 (ITU)ROOM
(Objectime)
Visual LanguageAnalysis phaseStandardization
Technology for a better society
Influences on UML 2.0
14
FORTRANAlgol Pascal
CNorwegian Computing Center
SIMULA(Nygaard, Dahl)
Xerox PARCSmallTalk (Kay)
AppleMacIntosh
OOA(Yourdon)
Objectory(Jacobsson) Booch
OMT (Rumbaugh)
UML 1.x (Rational/OMG)
SDL-88
MicrosoftWindows
Hoare-logic
CSPHoare Jones
VDMMilnerCCS
LOTOS (ISO)
COBOL
SQL
ER-model
SDL-92 (ITU)
Bell LabsC++
Sun
OODB
JAVA
Broy/StølenFocus
Corba
UML 2.0 (OMG)
SDL-2000 (ITU)
MSC-2000 (ITU) EJB Web services
MSC-92 (ITU)ROOM
(Objectime)
Class diagrams,Use Cases
Internal structure(Parts and Ports)Improved State Machines
Structured Sequence Diagrams Improved Components
Technology for a better society 15
Exercise: How do the other languages you have beenthought fit in the previous picture?
Technology for a better society
What language(s) to use?
Must have good mechanisms for abstraction– In the eighties, Simula was a very obvious choice
Must have adequate tooling– This was always the problem with Simula
• and still is a serious problem with UML
– This may now be reasonable argument in favor of Java
Must preferably be in use in "real systems"– This depends very much on what reality we are aiming at– Real systems are seldom made with only one language
• Multi‐language modeling / programming will increase
16
Technology for a better society
Papyrus UML Tool on Eclipse
18
Eclipse4.5 Mars
Papyrus
Get it!https://www.eclipse.org/
papyrus/
Technology for a better society
MAGIC of object orientation and modeling with UML
MetaAggregateGenerationIdentityConcepts
20
Technology for a better society
Class
Type
Pattern
Method
Function
Datatype
Object
Instance
Entity
Method call
Function call
VariablePrototype
Concepts (C in MAGIC)
Clone
21
Technology for a better society
A small story about Courses
The Software Engineering Course is a special CourseCourses contain LecturesThe lectures may generate questions
22
Technology for a better society
What are the boxes (Relata) ?
What are the arrows (Relations) ?course
SWEcourse
lectures
questions
is-a-special
consists-of
generates
A small Story with Boxes and Arrows
23
Technology for a better society
A small Story with UML class diagram
24
Class
Association
MemberEnd
Composition
NavigableMultiplicity
Generalization
Technology for a better society
A Small Story with Papyrus
25
Palette
Property view
Diagram canvas
Browsers
Technology for a better society
Exercise:
• Can Software Engineering course (SWEcourse) be held without lectures?
• Can there be lectures without questions asked?
• Can the very same lecture be given in two different courses?
• Can the very same question be posed to several lectures?
• If a course is cancelled, will all remaining lectures also be cancelled? (or "terminated")
27
Technology for a better society
A small story of UML instances
• Instance specifications are not classes
• Instance diagrams can be used to illustrate what kind of situations a class model may induce
• Instances are the manifestations of classes– Having a class does not mean
you have instances, but if you have an instance it needs to be an instance of (say) a class
28
Technology for a better society
Identity modifiers:
GeneralizationSubclassDerived ClassesExtension
Interface
ParametersOverloading
Redefined operationsVirtual proceduresVirtual functionsOverriding methods
Pointers to functions
Languages:
UMLSimulaC++Java
UML, Java
FORTRAN, Pascal, Algol, ...C++, Java
UMLSimula, SmalltalkC++Java
C, C++
Identity (I in MAGIC)
29
Technology for a better society
Subclassing or Inheritance
30
Generalization
SWEcourseinherits from
Course
Operation
redefined operation
Technology for a better society
A small story in Java
31
class Course {public abstract Grade exam() { };}
class SWECourse extends Course {public final Grade exam() { /* here we describe the concrete exam */ }}
Technology for a better society
FORTRAN Algol LISPSimulaSmalltalkJava
C++
NONE( only staticvariables)
PUSHon onestack generate
from heap
a stackand aheap
attermination POP
GarbageCollection
implicit(stack)andexplicit(heap)deallocation
Generation
Destruction
UMLStateMachines
UMLInteractions
send signals,create object
signals: at reception.state machine object: on final stateother objects: DestroyObjectAction
lifelines(i.e. theirrepresents)
at destruct
Generation (G in MAGIC)
• In O‐O systems the generation and destruction of objects are of great importance• Differences in memory management:
29
Technology for a better society
Generation depicted as an association
33
Navigable association
Questions are notowned by Lecture
Technology for a better society
objectaggregaterelation
Conceptaggregaterelation
Aggregate (A in MAGIC)
34
Composition
HiofSWCourse owns lecture_on_class_diagrams
Technology for a better society
Aggregate (Java)
Courselecture
Lecture
class Course {public abstract Grade exam() { };public Lecture[ ] lecture; /* the set of Lectures to be held here */
public Course(int nlectures) {lecture = new Lecture[nlectures]; /* create array of Lecture pointers */for (int i=1; i<nlectures; i++) { lecture[i] = new Lecture; } /* creating the actual Lecture objects */}}
35
Technology for a better society
Metamodel
Model
Defines
ChangeObserve
ProgramExecution
DataStructure
ModelingEnvironment
• Editor• Compiler• Interpreter• Debugger• Model database• Simulator• Validator• Text generation
Meta (M in MAGIC)
37
ModelingLanguage
describes defines
Technology for a better society
• What is the meta‐model?
• What is the modeling‐language?
• What is a model?
• What is program execution?
• What is the data structure?
38
Exercise: Explain the previous slide wrt the languageEnglish
Technology for a better society
The 4‐level meta hierarchy
Lev UML model Language Programming Language
M3 MOF metamodel MOF Grammar of BNF BNF?
M2 UML metamodel MOF Grammar of Java BNF
M1 UML user model UML Java user program Java
M0 Execution of user model
Execution of java program
39
Technology for a better society
Reflection / Metamodel (Java)
Course
lectureLecture
Class
getClass()
Class
“Course” “Lecture”
Method“exam”
getMethods()
Lecture
getClass()
42
Technology for a better society
MAGIC of UML (Summary)
M Meta metamodel and the meta hierarchyA Aggregate composition – the black diamondG Generate dynamic object creation, signalingI Identity generalization, redefinitionC Concept classes and associations
43
Technology for a better society
Exercise: Represent the drawing below in UML
44
Asset
Vulnerability
Threat
Consequence
Unwanted incident
Likelihood
Risk
Party
Treatment
Recommended