Models, Programs and Executable UML
-
Upload
ed-seidewitz -
Category
Technology
-
view
3.081 -
download
7
Transcript of Models, Programs and Executable UML
23 October 2011
Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
A division of Data Access Technologies, Inc.
Models, Programs and Executable UMLPresented at the First International Workshop on Combined Object-Oriented Modeling and Programming
Ed Seidewitz
Page 2 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
Models and Programs
What is a model?
A model is a set of statements in a modeling language about some system under study or domain.*
What is a program?
A program is a specification for a computation to be a executed on a computer.
* See Ed Seidewitz, “What Models Mean”, IEEE Software, September/October 2003 for more.
Page 3 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
Contentions
1. All programs are models.
2. Executable UML models are programs.
3. Executable UML models are useful.
Page 4 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
1. All programs are models
A program is a model of the specified computation, abstracting away from the details of how the computation is actually executed on a computer.
A programming language is a modeling language for creating models of execution.
Customer customer = customers.get(customerId);if (customer != null) {
int totalBalance = 0;for (Account account: customer.accounts) {
totalBalance += account.balance;}
}
Customer customer = customers.get(customerId);if (customer != null) {
int totalBalance = 0;for (Account account: customer.accounts) {
totalBalance += account.balance;}
}
…and a value called “totalBalance”……and a value called “totalBalance”…
… that is iteratively computed to be the sum of the customer’s account balances.
… that is iteratively computed to be the sum of the customer’s account balances.
There is a customer identified by “customerId”…There is a customer identified by “customerId”…
Java
Page 5 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
OO programs are also domain models
public class Bank {private String bankId;private Set<Customer> customers;private Set<Account> accounts;...
}
public class Bank {private String bankId;private Set<Customer> customers;private Set<Account> accounts;...
}
public class Customer {private String customerId;private Set<Account> accounts;...
}
public class Customer {private String customerId;private Set<Account> accounts;...
}
public class Account {private String accountId;private int balance = 0;private Set<Customer> accountOwners;
...}
public class Account {private String accountId;private int balance = 0;private Set<Customer> accountOwners;
...}
Classes are intended to reflect domain concepts.Classes are intended to reflect domain concepts.
Fields reflect properties of those concepts…Fields reflect properties of those concepts…
… or relationships with other concepts.… or relationships with other concepts.
Page 6 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
But make implementation commitmentspublic class Customer {
...private Set<Account> accounts = new HashSet<Account>();
public void addAccount(Account account) {if (account != null && !this.accounts.contains(account)) {
this.accounts.add(account);account.addAccountOwner(this);
}}...
}
public class Customer {...private Set<Account> accounts = new HashSet<Account>();
public void addAccount(Account account) {if (account != null && !this.accounts.contains(account)) {
this.accounts.add(account);account.addAccountOwner(this);
}}...
} public class Bank {...private Map<String, Account> customers = new HashMap<String, Customer>();
public Integer totalAccountBalance(String customerId) {Integer totalBalance = null;Customer customer = this.customers.get(customerId);if (customer != null) {
totalBalance = 0;for (Account account: customer.accounts) {
totalBalance += account.balance;}
}return totalBalance;
}...
}
public class Bank {...private Map<String, Account> customers = new HashMap<String, Customer>();
public Integer totalAccountBalance(String customerId) {Integer totalBalance = null;Customer customer = this.customers.get(customerId);if (customer != null) {
totalBalance = 0;for (Account account: customer.accounts) {
totalBalance += account.balance;}
}return totalBalance;
}...
}
Pick implementation classes for collections.Pick implementation classes for collections.
Deal with bidirectional relationships.Deal with bidirectional relationships.
Choose representations for efficient computation.Choose representations for efficient computation.
Decide on (generally sequential) control structuring.Decide on (generally sequential) control structuring.
Page 7 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
2. Executable UML models are programs
UML began as a notation for models of programs.
But UML 2 has constructs that allow the specification of Turing-complete computation models.
Foundational UML (fUML) provides precise execution semantics.Action Language for fUML (Alf) provides a textual notation.
customer = Customer -> select c (c.customerId == customerId);totalBalance = customer.accounts.balance -> reduce '+';customer = Customer -> select c (c.customerId == customerId);totalBalance = customer.accounts.balance -> reduce '+';
… and a value called “totalBalance” that is sum of the customer’s account balances.
… and a value called “totalBalance” that is sum of the customer’s account balances.
There is a customer identified by “customerId”…There is a customer identified by “customerId”…
Alf
Page 8 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
UML is common for domain modeling
public class Bank {private String bankId;private Set<Customer> customers;private Set<Account> accounts;...
}
public class Bank {private String bankId;private Set<Customer> customers;private Set<Account> accounts;...
}
public class Customer {private String customerId;private Set<Account> accounts;...
}
public class Customer {private String customerId;private Set<Account> accounts;...
}
public class Account {private String accountId;private int balance = 0;private Set<Customer> accountOwners;
...}
public class Account {private String accountId;private int balance = 0;private Set<Customer> accountOwners;
...}
The UML model directly corresponds to the program design…
The UML model directly corresponds to the program design…
…but abstracts away from implementation details (like collection classes).
…but abstracts away from implementation details (like collection classes).
It also shows some things implicit in the program, like association composition and bidirectionality.
It also shows some things implicit in the program, like association composition and bidirectionality.
Page 9 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
But diagrams are just notationclass Bank { public bankId: String; public customers: compose Customer[*]; public accounts: compose Account[*];}
class Bank { public bankId: String; public customers: compose Customer[*]; public accounts: compose Account[*];}
assoc AccountOwnership { public accountOwners: Customer[*]; public accounts: Account[*];}
assoc AccountOwnership { public accountOwners: Customer[*]; public accounts: Account[*];} class Account {
public accountId: String; public balance: Integer = 0;}
class Account { public accountId: String; public balance: Integer = 0;}
class Customer { public customerId: String;}
class Customer { public customerId: String;}
A UML class model has semantics independent of its mapping to any other language…
A UML class model has semantics independent of its mapping to any other language…
…which can be notated textually as well as graphically.
…which can be notated textually as well as graphically.
UML isn’t “just pictures”!
Page 10 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
Computation can be modeled, tooclass Bank {
public bankId: String;public customers: compose Customer[*];public accounts: compose Account[*];
public totalAccountBalance(in customerId: String): Integer[0..1] {
customer = this.customers -> select c (c.customerId == customerId);return customer.accounts.balance -> reduce '+';
}...
}
class Bank {public bankId: String;public customers: compose Customer[*];public accounts: compose Account[*];
public totalAccountBalance(in customerId: String): Integer[0..1] {
customer = this.customers -> select c (c.customerId == customerId);return customer.accounts.balance -> reduce '+';
}...
} The underlying semantics are based on data-flow, not an implicit von Neumann architecture.
The underlying semantics are based on data-flow, not an implicit von Neumann architecture.
These actions are inherently concurrent.These actions are inherently concurrent.
…with far fewer implementation commitments.…with far fewer implementation commitments.
Page 11 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
3. Executable UML models are useful
Executable UML models…
…can be tested, because they are programs
…don’t need to be “recoded”, they can be “compiled”
…abstract computation, not machine architecture
Page 12 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
The models are validated in a development/test environment
Programming in UML is just programming
The models are deployed in a production environment
Developers create fully executable models
Developers iteratively execute, test and update the models
…with models provisioned by a platform-specific “model compiler”.
…with models provisioned by a platform-specific “model compiler”.
But at a higher level of abstraction…But at a higher level of abstraction…
Past executable modeling approaches have demonstrated this can be done for
with production quality.
Page 13 Copyright © 2011 Data Access Technologies, Inc.(Model Driven Solutions)
23 October 2011
Resources
• Foundational UML (fUML)– Specification
http://www.omg.org/spec/FUML – Reference Implementation Project
http://www.modeldriven.org/fuml
• Action Language for fUML (Alf)– Specification
http://www.omg.org/spec/ALF – Reference implementation repository
http://lib.modeldriven.org/MDLibrary/trunk/Applications/Alf-Reference-Implementation
• /doc – Latest specification document (currently v1.0 Beta)• /dist – Parser for latest language version
– Alf implementation in Eclipse Papyrus UML toolhttps://bugs.eclipse.org/bugs/show_bug.cgi?id=329865
• Contact: [email protected], http://twitter.com/seidewitz