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

of 41 /41
And so to Code

Author: layla-claydon

Post on 01-Apr-2015

237 views

Category:

Documents


2 download

Embed Size (px)

TRANSCRIPT

  • Slide 1

And so to Code Slide 2 Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering Slide 3 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 Slide 4 Reverse Engineering Reverse engineering means generation of UML diagrams from code Demo Re-Engineer Slide 5 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 Slide 6 Mapping Designs to Code Creating Class Definitions from Class Diagram Creating Methods from Interaction Diagrams Using Collection Classes to implement relationships Code Slide 7 Creating Class Definitions from Class Diagram Slide 8 Creating Methods from Interaction Diagrams Slide 9 Collection Classes in Code Slide 10 .NET Sequence & Object Diagrams Exercises Slide 11 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() { } 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() { } Slide 12 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() { } 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 : Personcat : Cat Kick() Meow() Bite() Slide 13 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() { } 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 : Personcat : Cat Kick() Meow() [owner != null] Bite() [for each cat in cats] Slide 14 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() { } 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() { } Slide 15 UML Exercises : Class Diagrams for.NET Developers Slide 16 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 > Foxtrot Lima() Multiplicity at this end is ambiguous Slide 17 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(); } 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(); } Slide 18 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 Slide 19 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; } } Slide 20 Three Very Simple Use Cases Create New Supplier Delete Supplier Update Supplier Details Lets consider some coding issues! Slide 21 One Entity Class Slide 22 Three Control Classes Create New Supplier Delete Supplier Update Supplier Details Slide 23 One Boundary Class for all Three Use Cases Slide 24 One Boundary Class Slide 25 One Class to Talk to the Database Slide 26 Sequence Diagram for Create New Supplier Supplier Form Control Class Create Supplier Entity Class Supplier DB Connection DBSupplier Slide 27 Overview of the System Architecture Slide 28 Project Window for the entire application Slide 29 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. Slide 30 Another Case Study Slide 31 A Domain Model Slide 32 A Class Diagram Slide 33 Slide 34 Slide 35 Background to Naked Objects Slide 36 Best practice in contemporary business systems design splits an application into four principal layers Presentation Application, Process, Task or Controller Domain object model Persistence Slide 37 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 Slide 38 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 Slide 39 CarServ: A tale of two business applications Slide 40 Slide 41 Good Idea? One of the research topics for the coursework element of this module Final project???