1. All programs are models that specify computations to be executed on a computer, with programming languages serving as modeling languages.
2. Executable UML models are programs because UML 2 has constructs that allow specification of Turing-complete computation models with precise execution semantics.
3. Executable UML models are useful because they can be tested like programs without needing to be recoded, instead being compiled from models at a higher level of abstraction.
Developer Data Modeling Mistakes: From Postgres to NoSQL
Models, Programs and Executable UML
1. Models, Programs and Executable UML Presented at the First International Workshop on Combined Object-Oriented Modeling and Programming Ed Seidewitz
2.
3.
4.
5. OO programs are also domain models 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 Account { private String accountId; private int balance = 0; private Set<Customer> accountOwners; ... } Classes are intended to reflect domain concepts. Fields reflect properties of those concepts… … or relationships with other concepts.
6. But make implementation commitments 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; } ... } Pick implementation classes for collections. Deal with bidirectional relationships. Choose representations for efficient computation. Decide on (generally sequential) control structuring.
7.
8. UML is common for domain modeling 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 Account { private String accountId; private int balance = 0; private Set<Customer> accountOwners; ... } The UML model directly corresponds to the program design… … but abstracts away from implementation details (like collection classes). It also shows some things implicit in the program, like association composition and bidirectionality.
9. But diagrams are just notation class Bank { public bankId: String; public customers: compose Customer[*]; public accounts: compose Account[*]; } assoc AccountOwnership { public accountOwners: Customer[*]; public accounts: Account[*]; } class Account { public accountId: String; public balance: Integer = 0; } class Customer { public customerId: String; } A UML class model has semantics independent of its mapping to any other language… … which can be notated textually as well as graphically. UML isn’t “just pictures”!
10. Computation can be modeled, too 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. These actions are inherently concurrent. … with far fewer implementation commitments.
11.
12. Programming in UML is just programming … with models provisioned by a platform-specific “model compiler”. But at a higher level of abstraction… Past executable modeling approaches have demonstrated this can be done for with production quality. The models are validated in a development/test environment The models are deployed in a production environment Developers create fully executable models Developers iteratively execute, test and update the models