and so to code. forward, reverse, and round-trip engineering forward engineering reverse engineering...

41
And so to Code

Upload: layla-claydon

Post on 01-Apr-2015

248 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

And so to Code

Page 2: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Forward, Reverse, and Round-Trip Engineering

• Forward Engineering • Reverse Engineering• Round-Trip Engineering

Page 3: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Forward Engineering• Forward engineering means the generation of code from

UML diagrams• Many of the tools can only do the static models:

– They can generate class diagrams from code, but can't generate interaction diagrams.

– For forward engineering, they can generate the basic (e.g., Java) class definition from a class diagram, but not the method bodies from interaction diagrams.

• Demo Generate

Page 4: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Reverse Engineering• Reverse engineering means generation of UML diagrams

from code• Demo

Re-Engineer

Page 5: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Round-Trip Engineering• Round-trip engineering closes the loop

– the tool supports generation in either direction and can synchronize between UML diagrams and code, ideally automatically and immediately as either is changed.

• Demo

Page 6: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Mapping Designs to Code

• Creating Class Definitions from Class Diagram• Creating Methods from Interaction Diagrams• Using Collection Classes to implement

relationships Code

Page 7: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Creating Class Definitions from Class Diagram

Page 8: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Creating Methods from Interaction Diagrams

Page 9: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Collection Classes in Code

Page 10: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

.NET Sequence & Object Diagrams

Exercises

Page 11: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

1. Draw a sequence diagram to model the following code

public class Cat{

private Person owner;

public void Kick(){

Meow();owner.Bite();

}

public void Meow(){}

}

public class Person{

private Cat cat;

public void KickCat(){

// start herecat.Kick();

}

public void Bite(){}

}

public class Cat{

private Person owner;

public void Kick(){

Meow();owner.Bite();

}

public void Meow(){}

}

public class Person{

private Cat cat;

public void KickCat(){

// start herecat.Kick();

}

public void Bite(){}

}

Page 12: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Solution

public class Cat{

private Person owner;

public void Kick(){

Meow();owner.Bite();

}

public void Meow(){}

}

public class Person{

private Cat cat;

public void KickCat(){

// start herecat.Kick();

}

public void Bite(){}

}

public class Cat{

private Person owner;

public void Kick(){

Meow();owner.Bite();

}

public void Meow(){}

}

public class Person{

private Cat cat;

public void KickCat(){

// start herecat.Kick();

}

public void Bite(){}

}

/owner : Person cat : Cat

Kick()

Meow()Bite()

Page 13: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

2. Draw a sequence diagram to model the following code

public class Cat{

private Person owner;

public void Kick(){

Meow();if(owner != null){

owner.Bite();}

}

public void Meow(){}

}

public class Person{

private IList cats;

public void KickCat(){

// start hereforeach(Cat cat in cats){

cat.Kick();}

}

public void Bite(){}

}

public class Cat{

private Person owner;

public void Kick(){

Meow();if(owner != null){

owner.Bite();}

}

public void Meow(){}

}

public class Person{

private IList cats;

public void KickCat(){

// start hereforeach(Cat cat in cats){

cat.Kick();}

}

public void Bite(){}

}

/owner : Person cat : Cat

Kick()

Meow()

[owner != null] Bite()

[for each cat in cats]

Page 14: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Solution

public class Cat{

private Person owner;

public void Kick(){

Meow();if(owner != null){

owner.Bite();}

}

public void Meow(){}

}

public class Person{

private IList cats;

public void KickCat(){

// start hereforeach(Cat cat in cats){

cat.Kick();}

}

public void Bite(){}

}

public class Cat{

private Person owner;

public void Kick(){

Meow();if(owner != null){

owner.Bite();}

}

public void Meow(){}

}

public class Person{

private IList cats;

public void KickCat(){

// start hereforeach(Cat cat in cats){

cat.Kick();}

}

public void Bite(){}

}

Page 15: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

UML Exercises :

Class Diagrams for .NET Developers

Page 16: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Draw a class diagram based on the following code

public class Whiskey{

private IList tangos;

public Whiskey(){

tangos = new ArrayList();}

public void AddTango(Tango tango){

tangos.Add(tango);}

}

public class Tango : Foxtrot{

public void Lima(){}

}

public interface Foxtrot{

void Lima();}

public class Whiskey{

private IList tangos;

public Whiskey(){

tangos = new ArrayList();}

public void AddTango(Tango tango){

tangos.Add(tango);}

}

public class Tango : Foxtrot{

public void Lima(){}

}

public interface Foxtrot{

void Lima();}

Whiskey

Whiskey()AddTango(tango : Tango)

Tango

Lima()

*

tangos

<<interface>>Foxtrot

Lima()

Multiplicity at this end is ambiguous

Page 17: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Solutionpublic class Whiskey{

private IList tangos;

public Whiskey(){

tangos = new ArrayList();}

public void AddTango(Tango tango){

tangos.Add(tango);}

}

public class Tango : Foxtrot{

public void Lima(){}

}

public interface Foxtrot{

void Lima();}

public class Whiskey{

private IList tangos;

public Whiskey(){

tangos = new ArrayList();}

public void AddTango(Tango tango){

tangos.Add(tango);}

}

public class Tango : Foxtrot{

public void Lima(){}

}

public interface Foxtrot{

void Lima();}

Page 18: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

4. Draw a class diagram based on the following code

Party

# id : int

FullName() : string

Person

-firstName : string-lastName : string

FirstName() : stringFirstName(value : string)LastName() : stringLastName(value : string)FullName() : string = firstName + “ “ + lastName

Page 19: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Solution

public abstract class Party{

protected int id;

public abstract string FullName { get; }}

public class Person : Party{

private string firstName;private string lastName;

public string FirstName{

get { return firstName; }set { firstName = value; }

}

public string LastName{

get { return lastName; }set {lastName = value; }

}

public override string FullName{

get { return firstName + " " + lastName; }}

}

public abstract class Party{

protected int id;

public abstract string FullName { get; }}

public class Person : Party{

private string firstName;private string lastName;

public string FirstName{

get { return firstName; }set { firstName = value; }

}

public string LastName{

get { return lastName; }set {lastName = value; }

}

public override string FullName{

get { return firstName + " " + lastName; }}

}

Page 20: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Three Very Simple Use Cases

Create New Supplier

Delete Supplier

Update Supplier Details

Let’s consider some coding issues!

Page 21: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

One “Entity” Class

clsSupplier

colSuppliedProduct : CollectionlngSupplierID : LongstrCompanyName : StringstrContactName : StringstrContactTitle : StringstrAddress : StringstrCity : StringstrRegion : StringstrPostalCode : StringstrCountry : StringstrPhone : StringstrFax : String

Delete()FindByID()Update()

(from Project1)

<<Class Module>>

Page 22: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Three Control Classes

Create New Supplier

Delete Supplier

Update Supplier Details

Page 23: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

One Boundary Class for all Three Use Cases

Page 24: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

One Boundary Class

Page 25: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

One Class to Talk to the Database

Page 26: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Sequence Diagram for Create New Supplier

Supplier Form

Control Class

“Create Supplier”

Entity Class

“Supplier”

DB Connection

DBSupplier

Page 27: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Overview of the System Architecture

Page 28: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Project Window for the entire application

Page 29: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

More Sophisticated Use Cases

Perhaps we could ask the Customer object to:

– Project future sales to this customer. This would involve analysing past sales to identify trends. Implies the need for a “Customer Sales History” class not currently included in the model.

– Collect overdue payments. This would involve generating standard letters to be sent to the customer. Implies collaboration with a “Payment” class (associated with Order or Invoice?) not currently included in the model.

Page 30: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Another Case Study

Page 31: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

A Domain Model

Page 32: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

A Class Diagram

Page 33: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering
Page 34: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering
Page 35: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Background to Naked Objects

Page 36: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

‘Best practice’ in contemporary business systems design splits an application into four principal layers

Presentation

Application, Process, Task or Controller

Domain object model

Persistence

Page 37: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

But “The Naked Objects Pattern” eliminates the controller layer by encapsulating all business functionality on the entity objects

Presentation

Application, Process or Use-case controller

Domain object model

Persistence

Page 38: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

And has a generic presentation layer that automatically reflects the domain object model as an object-oriented user interface

Presentation

Application, Process or Use-case controller

Domain object model

Persistence

Page 39: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

CarServ: A tale of two business applications

Page 40: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering
Page 41: And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering

Good Idea?

• One of the research topics for the coursework element of this module

• Final project???