410 likes | 552 Views
And so to Code. Forward , Reverse, and Round-Trip Engineering. Forward Engineering Reverse Engineering Round-Trip Engineering. Generate. Forward Engineering. Forward engineering means the generation of code from UML diagrams Many of the tools can only do the static models:
E N D
Forward, Reverse, and Round-Trip Engineering • Forward Engineering • Reverse Engineering • Round-Trip Engineering
Generate 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
Re-Engineer Reverse Engineering • Reverse engineering means generation of UML diagrams from code • Demo
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
Mapping Designs to Code • Creating Class Definitions from Class Diagram • Creating Methods from Interaction Diagrams • Using Collection Classes to implement relationships Code
.NET Sequence & Object Diagrams Exercises
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 here cat.Kick(); } public void Bite() { } }
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 here cat.Kick(); } public void Bite() { } } /owner : Person cat : Cat Kick() Meow() Bite()
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 here foreach(Cat cat in cats) { cat.Kick(); } } public void Bite() { } } /owner : Person cat : Cat Kick() Meow() [owner != null] Bite() [for each cat in cats]
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 here foreach(Cat cat in cats) { cat.Kick(); } } public void Bite() { } }
UML Exercises : Class Diagrams for .NET Developers
Draw a class diagram based on the following code <<interface>> Foxtrot 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(); } Lima() tangos Whiskey Tango * Whiskey() AddTango(tango : Tango) Lima() Multiplicity at this end is ambiguous
Solution 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(); }
4. Draw a class diagram based on the following code Party # id : int FullName() : string Person • firstName : string • lastName : string FirstName() : string FirstName(value : string) LastName() : string LastName(value : string) FullName() : string = firstName + “ “ + lastName
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; } } }
Three Very Simple Use Cases Create New Supplier Update Supplier Details Delete Supplier Let’s consider some coding issues!
Three Control Classes Update Supplier Details Create New Supplier Delete Supplier
Create New Supplier Sequence Diagram for DB Connection DBSupplier Control Class “Create Supplier” Entity Class “Supplier” Supplier Form
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.
‘Best practice’ in contemporary business systems design splits an application into four principal layers Presentation Application, Process, Task or Controller Domain object model Persistence
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
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
Good Idea? • One of the research topics for the coursework element of this module • Final project???