Commit fae6792c authored by Gerson Sunyé's avatar Gerson Sunyé
Browse files

The presentation mapping UML to Java was restructured

parent 56aa4b92
......@@ -7,10 +7,13 @@
[comment]: # (DevOps)
----
## Plan
- Introduction
- Mapping designs to code
- Conclusion
- Construction Technologies
- Construction Processes
- Coding Tips
----
......@@ -26,7 +29,7 @@
## A Software Engineering Activity
![](resources/png/software-construction.png)
![Software Construction](resources/png/software-construction.png)
- An activity is not a phase.
- Referring to the construction as an activity does not imply a distinct phase.
......@@ -34,20 +37,22 @@
----
## Software Construction Sub-Activities
Software construction is more than just programming:
- Software Designing
- Coding and debugging
- Coding and Debugging
- Unit Testing
- Integration
- Integration Testing
- Construction Planning
- Implementation modeling
- Implementation Modeling
note:
The choice of construction method is a key aspect of the construction planning activity. The choice of construction method affects the extent to which construction prerequisites (e.g. Requirements analysis, Software design, .. etc) are performed, the order in which they are performed, and the degree to which they are expected to be completed before construction work begins. Construction planning also defines the order in which components are created and integrated, the software quality management processes, the allocation of task assignments to specific software engineers, and the other tasks, according to the chosen method.[1]
----
## Roadmap
1. Identify coding standards
......@@ -57,6 +62,7 @@ The choice of construction method is a key aspect of the construction planning a
1. Release for integration
----
## Construction Technologies
----
......@@ -73,9 +79,10 @@ The choice of construction method is a key aspect of the construction planning a
- Reduces the learning curve, but:
- Increases misinterpretation and confusion!<!-- .element: class="fragment highlight-red" -->
----
## Automatic Code Generation
- Code generate (part of) the code from the design model.
- Several tools available: Xtend, Acceleo, etc.
......@@ -83,16 +90,18 @@ note:
Writing generation templates is also “code construction”!
----
## Design by Contract
- Design-by-Contract
- Specification of class invariants and pre and post conditions of methods.
- Eiffel, JML, jContract.
- Eiffel, JML, jContract.
- Assertive programming
- Use of assertions inside methods.
- Test-driven development
----
## Contracts in Eiffel
```
......@@ -131,12 +140,11 @@ Writing generation templates is also “code construction”!
----
## Assertions
- Ensure the state of variables
- Improve code readability
- Improve error localization
- Can be disabled
- Ensure the state of variables.
- Improve code readability.
- Improve error localization.
- Can be disabled.
----
......@@ -163,6 +171,7 @@ public abstract class Application {
```
----
## Java Assertion with AssertJ
```java
......@@ -173,8 +182,8 @@ class Assertion {
// (...)
}
```
http://joel-costigliola.github.io/assertj/
http://joel-costigliola.github.io/assertj/
----
......@@ -195,14 +204,15 @@ Writing build scripts is also “code construction”
- If something goes wrong, it can determine what was changed and by who.
- CVS, SVN, Git, Mercurial, etc.
![](resources/tiff/git-logo.png)<!-- .element: style=" width:200px; position:absolute; right:0px;"-->
![Git](resources/png/git-logo.png)<!-- .element: style=" width:200px; position:absolute; right:0px;"-->
note:
In software engineering, software configuration management (SCM or S/W CM)[1] is the task of tracking and controlling changes in the software, part of the larger cross-disciplinary field of configuration management.[2] SCM practices include revision control and the establishment of baselines. If something goes wrong, SCM can determine what was changed and who changed it. If a configuration is working well, SCM can determine how to replicate it across many hosts.
In software engineering, software configuration management (SCM or S/W CM) [1] is the task of tracking and controlling changes in the software, part of the larger cross-disciplinary field of configuration management.[2] SCM practices include revision control and the establishment of baselines. If something goes wrong, SCM can determine what was changed and who changed it. If a configuration is working well, SCM can determine how to replicate it across many hosts.
----
## Automatic Testing
- Automatic execution of unit tests:
- Shortens time to defect detection
- Increases personal discipline
......@@ -210,11 +220,12 @@ In software engineering, software configuration management (SCM or S/W CM)[1] is
- Test-driven development
- JUnit, TestNG, Selenium, etc.
![](resources/tiff/junit-logo.png)<!-- .element: style=" width:200px; position:absolute; right:0px;"-->
![JUnit](resources/png/junit-logo.png)<!-- .element: style=" width:200px; position:absolute; right:0px;"-->
----
## Code Refactoring
- Refactoring improves the design of existing code without changing its behavior
- Examples: change of a class name, creation of an abstract class, extraction of the interface of class, etc.
......@@ -225,7 +236,7 @@ In software engineering, software configuration management (SCM or S/W CM)[1] is
- Legacy code (or other software) may be an important source of information
- Automatic analysis/modification of legacy code: MoDisco, Spoon, etc
![](resources/tiff/modisco-logo.png)<!-- .element: style=" width:200px; position:absolute; right:0px;"-->
![Modisco](resources/png/modisco-logo.png)<!-- .element: style=" width:200px; position:absolute; right:0px;"-->
----
......@@ -239,37 +250,44 @@ In software engineering, software configuration management (SCM or S/W CM)[1] is
----
## Continuous Integration
## Popular Tools
![](resources/tiff/continuous-integration.png)
- Programming languages:
- GPL: Java, Scala, C++
- DSL: Protobuf, Haxe
- IDE: Eclipse, NetBeans, IntelliJ
- Build: Ant, Maven, Gradle
- Static analysis: PMD, Findbugs
- Profiling: JProfile
----
## DevOps
## Construction Processes
![](resources/png/devops.png)
----
## Continuous Integration
![CI](resources/png/continuous-integration.png)
----
## Construction Tools
- Programming languages:
- GPL: Java, Scala, C++
- DSL: Protobuf, Haxe
- IDE: Eclipse, NetBeans, IntelliJ
- Build: Ant, Maven, Gradle
- Static analysis: PMD, Findbugs
- Profiling: JProfile
## DevOps
![DevOps](resources/png/devops.png)
----
## Coding Tips
----
## Avoid Repetition
![](resources/jpg/repetition.jpg)
![Repetition](resources/jpg/repetition.jpg)
----
## Avoid Complexity
```c
......@@ -282,6 +300,7 @@ float InvSqrt (float x){
return x;
}
```
The inverse square root implementation in Quake 3
http://www.gamedev.net
......@@ -291,6 +310,7 @@ http://www.gamedev.net
## Keep Things Simple
Replace:
```java
if (booleanExpression) {
return true;
......@@ -298,7 +318,9 @@ if (booleanExpression) {
return false;
}
```
by:
```java
return booleanExpression;
```
......@@ -306,13 +328,16 @@ return booleanExpression;
----
And:
```java
if (condition) {
return x;
}
return y;
```
by:
```java
return (condition ? x : y);
```
......@@ -342,7 +367,9 @@ In some cases (using collection of objects) this law can be “release”.
Iterators, for instance, break this law.
----
## Learn Code Smells
- Code smells are “warnings signs” of deeper problems.
- For instance: god classes, feature envy, long methods, too many parameters, nested if statements, etc.
......@@ -351,17 +378,18 @@ http://wiki.c2.com/?CodeSmell
----
## Think Globally, Program Locally
- Make variables as local as possible and as invisible as possible
- If you have the choice between protected or private visibility, choose private.
- Making attributes protected gives objects of subclasses access to attributes of their super-classe.
----
## Depend on Interfaces, not on Implementations
```java
class Dependency {
Collection<String> names = new LinkedList<
String>();
Collection<String> names = new LinkedList<String>();
Collection<String> getNames(){}
void addMoreNames(Collection<String> others){}
}
......@@ -371,6 +399,7 @@ note:
If a different implementation is needed (ArrayList, SynchronizedArrayList, etc.), maintenance is simplified.
----
## Coding Conventions
- Generic conventions (for Java):
......@@ -382,9 +411,8 @@ If a different implementation is needed (ArrayList, SynchronizedArrayList, etc.)
- [Apache Coding Standards](https://portals.apache.org/development/code-standards.html)
----
## Conclusion
- Code construction is not only implementation.
- It is not a phase of the development process.
- It is not a phase of the development process.
\ No newline at end of file
......@@ -5,9 +5,8 @@ Gerson Sunyé
gerson.sunye@univ-nantes.fr
----
## Licence
This work is licensed under a [Creative Commons Attribution-NonCommercial 4.0 International License](http://creativecommons.org/licenses/by-nc/4.0/).
......@@ -15,14 +14,20 @@ This work is licensed under a [Creative Commons Attribution-NonCommercial 4.0 In
[![Creative Commons License](https://i.creativecommons.org/l/by-nc/4.0/88x31.png)](http://creativecommons.org/licenses/by-nc/4.0/)
----
## References
- P. Bourque and R.E. Fairley, eds., [Guide to the Software Engineering Body of Knowledge (SWEBOK)](https://www.swebok.org), Version 3.0, IEEE Computer Society, 2014.
- [«Code Complete»](https://www.microsoftpressstore.com/store/code-complete-9780735619678). Steve McConnell. 2nd edition. Microsoft Press.
- «JUnitTest Infected: Programmers Love Writing Tests». Erich Gamma and Kent Beck. Java Report: Volume 3, Number 7. July 1998.
- «Extreme programming explained: embrace change. Kent Beck. Addison-Wesley, 1999.
- «Test-Driven Development: By Example». Kent Beck. Addison-Wesley, 2002.
- «Test-Driven Development: A Practical Guide». David Astels. Prentice Hall, 2003.
----
## More references
- «Test-Driven Development: By Example». Kent Beck. Addison-Wesley, 2002.
- «Test-Driven Development: A Practical Guide». David Astels. Prentice Hall, 2003.
- «Head First Design Patterns: A Brain-Friendly Guide». Bert Bates, Kathy Sierra, Eric Freeman, Elisabeth Robson. O'Reilly Media, June 2009.
----
......
## Mapping UML Designs to Code
### Structural Aspects
# Mapping UML Designs to Code
## Structural Aspects
----
## Plan
- Introduction
- Creating an Implementation Strategy
- **Introduction**
- Implementation Strategy
- Classes
- Attributes
- Associations
----
## Mapping Designs to Code
Translating a UML model to object-oriented source code is a difficult task:
- UML has several diagrams representing different aspects of the model.
- The mapping from UML concepts (classes, associations, signals, states, operations, etc.) to OO concepts (classes, fields, and methods) is not trivial.
- UML lacks semantics: there is no universal rule for mapping design to code.
......@@ -24,6 +26,7 @@ Translating a UML model to object-oriented source code is a difficult task:
[comment]: # (UML Model => Object-Oriented Source Code)
----
## Implementation Strategy
- A set of rules that specifies how to translate design models to code.
......@@ -32,68 +35,65 @@ Translating a UML model to object-oriented source code is a difficult task:
- Occasionally: a specific UML profile (set of tags and stereotypes), generation templates, configurations, etc.
----
## Implementation Roadmap
- For each component:
1. Implement component
1. Implement unit test
1. For each class in component:
1. Implement class
1. Implement unit tests
- Implement component
- Implement unit test
- For each class in a component:
- Implement class
- Implement unit tests
----
## Plan
- Introduction
- Creating an Implementation Strategy
- **Implementation Strategy**
- Classes
- Attributes
- Associations
----
## Creating an Implementation Strategy
1. Rules for class implementation.
1. Type correspondence table.
2. Rules for multi-valued attribute implementation.
3. Rules for multi-valued attribute implementation.
3. Rules for unidirectional association implementation.
3. Rules for bidirectional association implementation.
## Creating an Implementation Strategy
----
## Plan
An implementation strategy must cotain rules for:
- Introduction
- Creating an Implementation Strategy
- Classes
- Attributes
- Associations
1. Class implementation.
1. Type correspondence.
1. Mono-valued attribute implementation.
1. Multi-valued attribute implementation.
1. Unidirectional association implementation.
1. Bidirectional association implementation.
----
## Step 1
### Class Implementation
### Rules for Class Implementation
----
## Class Implementation
Approaches:
Different approaches:
1. Simple correspondence.
- Simple correspondence.
- For each UML class, create a Java class.
2. Class-Interface.
- Class-Interface.
- For each UML class, create a pair (class, interface)
3. Generation Gap.
- For each UML class, create a triple (interface, abstract class, concrete class)
- Generation Gap Pattern.
- For each UML class, create a triple (interface, abstract class, concrete class)
----
## Simple Correspondence Approach
### For each UML class, create a Java class.
![](resources/png/htmlpage.png)<!-- .element: style="position:absolute; left:0px; top:350px; width:300px;" -->
## Simple Correspondence Approach
For each UML class, create a Java class.
![HTMLPage](resources/png/htmlpage.png)<!-- .element: style="position:absolute; left:0px; top:350px; width:300px;" -->
```java
public class HTMLPage {
......@@ -102,23 +102,24 @@ public class HTMLPage {
```
<!-- .element: style="position:absolute; left:320px; top:400px; width:750px" -->
----
## Class-Interface Approach
### For each UML class, create a pair (class, interface)
![](resources/png/htmlpage-interface.png)
For each UML class, create a pair (class, interface)
![HTMLPae Interface](resources/png/htmlpage-interface.png)
Here, «Implementation Model» is a graphical representation for Java.
Here, the «Implementation Model» is a graphical representation for Java.
note:
Yes, UML can also be used to represent implementation models.
----
### For each UML class, create a pair (class, interface)
![](resources/png/htmlpage.png)<!-- .element: style="position:absolute; left:0px; top:200px; width:300px;" -->
For each UML class, create a pair (class, interface)
![HTMLPage](resources/png/htmlpage.png)<!-- .element: style="width:20%;" -->
```java
public interface HTMLPage {
......@@ -128,30 +129,32 @@ public interface HTMLPage {
public class BasicHTMLPage implements HTMLPage {
// (...)
}
```
<!-- .element: style="position:absolute; left:320px; top:200px; width:750px" -->
```
<!-- .element: style="width:750px;" -->
----
## Class-Interface Approach Wrap-up
- Useful when the class `HTMLPage` is used in different contexts: DAO, RPC, Persistence, Tests, etc.
----
## Generation Gap Approach
- Based on the «Generation Gap» pattern.
----
### For each UML class, create a triple (interface, abstract class, concrete class)
![](resources/png/htmlpage-generation-gap.png)
### For each UML class, create a triple (interface, abstract class, concrete class)
![Generation Gap](resources/png/htmlpage-generation-gap.png)
----
### For each UML class, create a triple (interface, abstract class, concrete class)
![](resources/png/htmlpage.png)<!-- .element: style="position:absolute; left:0px; top:200px; width:200px;" -->
For each UML class, create a triple (interface, abstract class, concrete class)
![HTMLPage](resources/png/htmlpage.png)<!-- .element: style="position:absolute; left:0px; top:200px; width:200px;" -->
```java
public interface HTMLPage {
......@@ -169,6 +172,7 @@ public class UserHTMLPage extends BasicHTMLPage {
<!-- .element: style="position:absolute; left:220px; top:200px; width:750px" -->
----
## Generation Gap Wrap-up
- Useful in a automatic code generation context:
......@@ -177,7 +181,9 @@ public class UserHTMLPage extends BasicHTMLPage {
- Class/Interface proliferation.
----
## Approach extension
### Use a common interface
![](resources/png/common-interface.png)<!-- .element: style="position:absolute; left:0px; top:200px; width:200px;" -->
......@@ -193,19 +199,32 @@ public interface Common {
<!-- .element: style="position:absolute; left:220px; top:200px; width:750px" -->
----
## Common Interface
- Facility methods available for all objects.
- Can be extended with _reflexion_ methods, e.g.,
- `get(String attrName)`
- `call(String methodName)`
- Can be extended with _reflexion_ methods, e.g.,
- `Object get(String attrName)`
- `void call(String methodName)`
- etc.
----
## Step 2
### Propose a type correspondence table
## Implementation Strategy Rules
1. Class implementation.
1. **Type correspondence**.
1. Mono-valued attribute implementation.
1. Multi-valued attribute implementation.
1. Unidirectional association implementation.
1. Bidirectional association implementation.
----
## Type Correspondence Table
----
## UML Types
Base UML only has 5 primitive types. However, new datatypes can be added using «profiles».
......@@ -219,10 +238,11 @@ String | "to be or not to be"
Real | 1.5, 3.14, ...
----
## Correspondence Table (example)
UML | Java | MySQL | TypeScript
--|--
## Correspondence Table (example)
UML | Java | MySQL | TypeScript
--|--
`Integer` | `java.lang.Integer` | `BIGINT` | `number`
`Boolean` | `java.lang.Boolean` | `BOOLEAN` | `boolean`
`UnlimitedNatural` | `java.lang.Integer` | `TINYINT` | `number`
......@@ -237,10 +257,11 @@ Independently from the choice, it is important to mention that it is difficult t
This table can be improved using stereotypes, tags, OCL invariants, etc.
----
## Another Correspondence Table
UML | Java
--|--
## Another Correspondence Table
UML | Java
--|--
`Integer` | `int`
`Boolean` | `boolean`
`UnlimitedNatural` | `int`
......@@ -248,22 +269,19 @@ UML | Java
`Real` | `double`
----
## Plan
- Introduction
- Creating an Implementation Strategy
- Classes
- Attributes
- Associations
## Implementation Strategy Rules
----
## Step 3
### Monovalued Attribute Implementation
1. Class implementation.
1. Type correspondence.
1. **Mono-valued attribute implementation**.
1. Multi-valued attribute implementation.
1. Unidirectional association implementation.
1. Bidirectional association implementation.
----
![](resources/png/open-parenthesis.png)
![Open](resources/png/open-parenthesis.png)
----
......@@ -271,31 +289,31 @@ UML | Java
Attributes are a typed structural property, which specify the structure of all instances of a given classifier.
![](resources/png/htmlpage.png)