SlideShare a Scribd company logo
1 of 36
Download to read offline
UML for Java Developers
Model Constraints & The Object Constraint
               Language
             Jason Gorman




              © Jason Gorman 2005. All rights reserved.
quot;I am currently working on a
team which is [in] the process
of adopting RUP and UML
                                            UML for Java Developers (5 Days)
standards and practices. After              Since Autumn 2003, over 100,000 Java and .NET developers have
one of our design sessions, I               learned the Unified Modeling Language from Parlez UML
needed to lookup some                       (http://www.parlezum l.com) , making it one of the most popular
information and came across                 UML training resources on the Internet.
your site. Absolutely great!
Most [of] the information I've
had questions about is                      UML for Java Developers is designed to accelerate the learning
contained within your tutorials             process by explaining UML in a language Java developers can
and then some.quot;                             understand – Java!


                                            From Requirements to a Working System
quot;Really great site... I have been           Many UML courses focus on analysis and high-level design, falling
trying to grasp UML since the               short of explaining how you get from there to a w orking system. UML
day I saw Visual Modeler. I
knew a few things but there                 for Java Developers takes you all the w ay from system
were gaps. Thanks to your site              requirements to the finished code because that, after all, is w hy we
they have shrunk                            model in the first place.
considerably.quot;
                                            Learning By Doing
                                            UML modeling is a practical skill, like driving a car or flying a plane.
quot;I went on a UML training
                                            Just as w e don’t learn to drive just by looking at Pow erPoint
course three months ago, and
came out with a big folder full             presentations, you cannot properly learn UML w ithout getting plenty
of hand-outs and no real                    of practice at it.
understanding of UML and how
to use it on my project. I spent            Your skills w ill be developed by designing and building a w orking
a day reading the UML for                   piece of software, giving you a genuine understanding of how UML
.NET tutorials and it was a                 can be applied throughout the development lifecycle.
much easier way to learn.
'Here's the diagram. Now
here's the code.' Simple.quot;
                                             www.parlezuml.com/training.htm

                                    advertisement


               © Jason Gorman 2005. All rights reserved.
UML for Java Developers covers the most useful aspects of the
                      UML standard, applying each notation w ithin the context of an
                      iterative, object oriented development process

            Use Case Diagrams                                  Object Diagrams & Filmstrips
            Model the users of the system                      Model snapshots of the running
            and the goals they can achieve                     system and show how actions
            by using it                                        change object state

            Class Diagrams                                     Implementation Diagrams
            Model types of objects and                         Model the physical components of a
            the relationships between                          system and their deployment
            them.                                              architecture


            Sequence Diagrams                                  Packages &
            Model how objects interact                         Model Management
            to achieve functional goals                        Organise your logical and physical
                                                               models with packages

            Activity Diagrams
                                                               Object Constraint Language
            Model the flow of use cases
                                                               Model business rules and create
            and single and multi-threaded                      unambiguous specifications
            code

            Statechart Diagrams                                User Experience Modeling
            Model the behaviour of objects                     Design user-centred systems with
            and event-driven applications                      UML



            Design Principles                                   Design Patterns
            Create well-designed software                       Apply proven solutions to common
            that’s easier to change and                         OO design problems
            reuse

www.parlezuml.com/training.htm

  © Jason Gorman 2005. All rights reserved.
UML Diagrams Don’t Tell Us
          Everything


                                                                        children

parents   0..2
                                                             parents
                            valid instance of                              Bill : Person
                                                                                              parents
                 *
     Person
                                                                                   children
                 children




                            © Jason Gorman 2005. All rights reserved.
Constraints Make Models More
             Precise


                                                                                     children

parents   0..2
                                                                          parents
                                    not a valid instance of                             Bill : Person
                                                                                                           parents
                     *
     Person
                                                                                                children
                     children




                 {cannot be own descendant or
                          ancestor }




                                         © Jason Gorman 2005. All rights reserved.
What is the Object Constraint
            Language?
• A language for expressing necessary extra
  information about a model
• A precise and unambiguous language that
  can be read and understood by developers
  and customers
• A language that is purely declarative – ie, it
  has no side-effects (in other words it
  describes what rather than how)

                 © Jason Gorman 2005. All rights reserved.
What is an OCL Constraint?
• An OCL constraint is an OCL expression
  that evaluates to true or false (a Boolean
  OCL expression, in other words)




                © Jason Gorman 2005. All rights reserved.
OCL Makes Constraints
    Unambiguous
{ancestors = parents->union(parents.ancestors->asSet())}
{descendants = children->union(children.descendants->asSet())




                                               parents    0..2


                                 ancestors                              *
                                                     Person
                                         *                              children

                                                     *    descendants
                      /family tree




                         {ancestors->excludes(self) and descendants->excludes(self) }




                            © Jason Gorman 2005. All rights reserved.
Introducing OCL – Constraints &
                  Contexts
                                             {ancestors = parents->union(parents.ancestors->asSet())}
                                             {descendants = children->union(children.descendants->asSet())




                                                                                              parents    0..2


                                                                                  ancestors                         *
                                                                                                    Person
   Q: To what which type this constraint apply?                                           *                         children
   A: Person
                                                                                                   *     descendants
                                                                       /family tree


context Person
  context Person
inv: ancestors->excludes(self) and descendants->excludes(self)
  inv: ancestors->excludes(self) and descendants->excludes(self)



 Q: When does this constraint apply?
                                                                          {ancestors->excludes(self) and descendants->excludes(self) }
 A: inv = invariant = always




                                              © Jason Gorman 2005. All rights reserved.
Operations, Pre & Post-
                           conditions
           <<enumeration>>
                 Sex
       MALE = 1
       FEMALE = 2



                                                Person
                                                                      0..1
                                   sex : Sex
optional constraint name                                              spouse
                                   marry(p : Person)


                                                                          applies to the marry() operation of the type Person

           context Person::marry(p : Person)
            context Person::marry(p : Person)
           pre cannot_marry_self: not (p = self)
            pre cannot_marry_self: not (p = self)
           pre not_same_sex: not (p.sex = self.sex)                                                    comments start with --
            pre not_same_sex: not (p.sex = self.sex)
           -- neither person can be married already
            -- neither person can be married already
           pre not_already_married: self.spouse->size() = 0 and p.spouse->size() = 0
            pre not_already_married: self.spouse->size() = 0 and p.spouse->size() = 0
           post : self.spouse = p and p.spouse = self
            post : self.spouse = p and p.spouse = self




                                               © Jason Gorman 2005. All rights reserved.
Design By Contract :assert
                                                          class Sex
                                                            class Sex
                                                          {
                                                            {
                                                                           static final int MALE = 1;
                                                                             static final int MALE = 1;
                                                                           static final int FEMALE = 2;
                                                                             static final int FEMALE = 2;
                                                          }
                                                              }


                                                          class Person
                                                            class Person
                                                          {
                                                            {
                                                                           public int sex;
                                                                            public int sex;
                                                                           public Person spouse;
                                                                            public Person spouse;                            self

                                                                           public void marry(Person p)
                                                                             public void marry(Person p)
                                                                           {
                                                                             {
                                                                                            assert p != this;
                                                                                             assert p != this;
context Person::marry(p : Person)
  context Person::marry(p : Person)                                                         assert p.sex != this.sex;
pre cannot_marry_self: not (p = self)                                                        assert p.sex != this.sex;
  pre cannot_marry_self: not (p = self)
pre not_same_sex: not (p.sex = self.sex)                                                    assert this.spouse = null && p.spouse = null;
  pre not_same_sex: not (p.sex = self.sex)                                                   assert this.spouse = null && p.spouse = null;
-- neither person can be married a lready
  -- neither person can be married a lready
pre not_already_married: self.spouse->size() = 0 and p.spouse->size() = 0
  pre not_already_married: self.spouse->size() = 0 and p.spouse->size() = 0
post : self.spouse = p and p.spouse = self                                                  this.spouse = p;
  post : self.spouse = p and p.spouse = self                                                  this.spouse = p;
                                                                                            p.spouse = this;
                                                                                              p.spouse = this;
                                                                           }                                     self.spouse->size = 0
                                                                               }
                                                          }
                                                              }




                                                     © Jason Gorman 2005. All rights reserved.
Defensive Programming : Throwing Exceptions
    class Person
      class Person
    {
      {
                     public int sex;
                      public int sex;
                     public Person spouse;
                      public Person spouse;


                     public void marry(Person p) throws ArgumentException {
                      public void marry(Person p) throws ArgumentException {
                                     if(p == this) {
                                       if(p == this) {
                                                       throw new ArgumentException(quot;cannot marry selfquot;);
                                                         throw new ArgumentException(quot;cannot marry selfquot;);
                                     }
                                       }
                                     if(p.sex == this.sex) {
                                       if(p.sex == this.sex) {
                                                       throw new ArgumentException(quot;spouse is sa me sexquot;);
                                                         throw new ArgumentException(quot;spouse is sa me sexquot;);
                                     }
                                       }
                                     if((p.spouse != null || this.spouse != null) {
                                       if((p.spouse != null || this.spouse != null) {
                                                       throw new ArgumentException(quot;already marriedquot;);
                                                         throw new ArgumentException(quot;already marriedquot;);
                                     }
                                       }

                                     this.spouse = p;
                                       this.spouse = p;
                                     p.spouse = this;
                                       p.spouse = this;
                     }
                         }
    }
        }




                                              © Jason Gorman 2005. All rights reserved.
Referring to previous values and
        operation return values

            Account
balance : Real = 0

deposit(amount : Real)
withdraw(a mount : Real)                                                 balance before execution of operation
getBalance() : Real




                           context Account::withdraw (amount : Real)
                            context Account::withdraw (amount : Real)
                           pre: amount <= balance
                            pre: amount <= balance
                           post: balance = balance@pre - amount
                            post: balance = balance@pre - amount
                           context Account::getBalance() : Real
                            context Account::getBalance() : Real
                           post : result = balance
                            post : result = balance




                             return value of operation



                                  © Jason Gorman 2005. All rights reserved.
@pre and result in Java
                                                                       class Account
                                                                         class Account
                                                                       {
                                                                         {
                                                                                         private float balance = 0;
    context Account::withdraw(amount : Real)                                              private float balance = 0;
     context Account::withdraw(amount : Real)
    pre: amount <= balance
     pre: amount <= balance
    post: balance = balance@pre - amount                                                 public void withdraw(float amount) {
     post: balance = balance@pre - amount                                                 public void withdraw(float amount) {
                                                                                                          assert amount <= balance;
    context Account::getBalance() : Real                                                                   assert amount <= balance;
     context Account::getBalance() : Real
    post : result = balance
     post : result = balance                                                                              balance = balance - a mount;
                                                                                                           balance = balance - a mount;
                                                                                         }
                                                                                             }
public void testWithdrawWithSufficientFunds() {
                Account account = new Account();                                         public void deposit(float a mount) {
                                                                                           public void deposit(float a mount) {
                                                                                                          balance = balance + a mount;
                                                                                                           balance = balance + a mount;
                account.deposit(500);                                                    }
                                                                                           }

                float balanceAtPre = account.getBalance();                               public float getBalance() {
                                                                                           public float getBalance() {
                                                                                                           return balance;
                                                                                                             return balance;
                float amount = 250;                                                      }                                      result = balance
                                                                                           }
                                                                       }
                                                                           }
                account.withdraw(amount);


                assertTrue(account.getBalance() == balanceAtPre – a mount);
}


                                                                                                   balance = balance@pre - amount

                                                       © Jason Gorman 2005. All rights reserved.
OCL Basic Value Types
              Account                      • Integer : A whole number of any size
balance : Real = 0
name : String
                                           • Real : A decimal number of any size
id : Integer
isActive : Boolean                         • String : A string of characters
deposit(amount : Real)
withdraw(a mount : Real)                   • Boolean : True/False

  id : Integer             balance : Real = 0                    name : String    isActive : Boolean


  int id;                  double balance = 0;                   string na me;    boolean isActive;

  long id;                 float balance = 0;                    char[] na me;

  byte id;

  short id;




                                      © Jason Gorman 2005. All rights reserved.
Operations on Real and Integer Types
Operation          Notation                               Result type
equals             a =b                                   Boolean
not equals         a <> b                                 Boolean
less               a <b                                   Boolean
more               a >b                                   Boolean
less or equal      a <= b                                 Boolean
more or equal      a >= b                                 Boolean
plus               a +b                                   Integer or Real
minus              a -b                                   Integer or Real
multiply           a*b                                    Integer or Real
divide             a /b                                   Real
modulus            a.mod(b)                               Integer
integer division   a.div(b)                               Integer
absolute value     a.abs                                  Integer or Real
maximum            a.max(b)                               Integer or Real
minimum            a.min(b)                               Integer or Real
round              a.round                                Integer
floor              a.floor                                Integer

     Eg, 6.7.floor() = 6
                   © Jason Gorman 2005. All rights reserved.
Operations on String Type


Operation            Expression                                    Result type
concatenation        s.concat(string)                              String
size                 s.size                                        Integer
to lower case        s.toLower                                     String
to upper case        s.toUpper                                     String
substring            s.substring(int, int)                         String
equals               s1 = s2                                       Boolean
not equals           s1 <> s2                                      Boolean

Eg, ‘jason’.concat(‘ gorman’) = ‘jason gorman’
Eg, ‘jason’.substring(1, 2) = ‘ja’

                       © Jason Gorman 2005. All rights reserved.
Operations on Boolean Type

Operation        Notation                                            Result type
or               a or b                                              Boolean
and              a and b                                             Boolean
exclusive or     a xor b                                             Boolean
negation         not a                                               Boolean
equals           a=b                                                 Boolean
not equals       a <> b                                              Boolean
implication      a implies b                                         Boolean
if then else     if a then b1 else b2 endif                          type of b

Eg, true or false = true
Eg, true and false = false
                         © Jason Gorman 2005. All rights reserved.
Navigating in OCL Expressions
                     accounts                holder
   Account                                                    Customer
                     *                           1




In OCL:

account.holder

Evaluates to a customer object who is in the role holder for that association

And:

customer.accounts

Evaluates to a collection of Account objects in the role accounts for that association



                                                       Account account = new Account();
                                                        Account account = new Account();
                                                       Customer customer = new Customer();
                                                        Customer customer = new Customer();


                                                       customer.accounts = new Account[] {account};
                                                        customer.accounts = new Account[] {account};
                                                       account.holder = customer;
                                                        account.holder = customer;




                                              © Jason Gorman 2005. All rights reserved.
Navigability in OCL Expressions

                                             b
     A                                                            B
                                             1




         a.b is allowed

         b.a is not allowed – it is not navigable
                  class A
                    class A
                  {
                    {
                                     public B b;
                                      public B b;
                  }
                      }

                  class B
                    class B
                  {
                    {
                  }
                    }

                      © Jason Gorman 2005. All rights reserved.
Calling class features

                Account
id : Integer
status : enum{active, frozen, closed}
balance : Real
nextId : Integer

deposit(amount : Real)                               context Account::createNew() : Account
                                                      context Account::createNew() : Account
withdraw(a mount : Real)                             post: result.oclIsNew() and
fetch(id : Integer) : Account                         post: result.oclIsNew() and
                                                           result.id = Account.nextId@pre and
                                                            result.id = Account.nextId@pre and
                                                           Account.nextId = result.id + 1
                                                            Account.nextId = result.id + 1




                                        © Jason Gorman 2005. All rights reserved.
Enumerations in OCL

                 Account
                                                        context Account::withdraw(amount : Real)
                                                         context Account::withdraw(amount : Real)
balance : Real                                          pre: amount <= balance
                                                         pre: amount <= balance
deposit(amount : Real)                                  pre: status = AccountStatusKind.ACT IVE
                                                         pre: status = AccountStatusKind.ACT IVE
withdraw(a mount : Real)                                post: balance = balance@pre - amount
                                                         post: balance = balance@pre - amount

                                    1     status

                               <<enumeration>>
                               AccountStatusKind

                               ACTIVE
                               FROZEN
                               CLOSED




                                 © Jason Gorman 2005. All rights reserved.
Collections in OCL
                         accounts                  holder
              Account                                               Customer
                         *                             1
       balance : Real
       id : Integer




customer.accounts.balance = 0 is not allowed

customer.accounts->select(id = 2324).balance = 0 is allowed




                                    © Jason Gorman 2005. All rights reserved.
class Account
                        class Account


Collections in        {
                        {
                                         public double balance;
                                          public double balance;
                                         public int id;
                                          public int id;


Java                  }
                          }


                      class Customer
                        class Customer
                      {
                        {
                                         Account[] accounts;
                                          Account[] accounts;


                                         public Account SelectAccount(int id)
                                           public Account SelectAccount(int id)
                                         {
                                           {
                                                          Account selected = null;
                                                           Account selected = null;

                                                         for(int i = 0; i < accounts.length; i++)
                                                           for(int i = 0; i < accounts.length; i++)
                                                         {
                                                           {
                                                                            Account account = accounts[i];
                                                                              Account account = accounts[i];
                                                                            if(account.id = id)
                                                                              if(account.id = id)
                                                                            {
                                                                              {
                                                                                              selected = account;
                                                                                                selected = account;
                                                                                              break;
                                                                                                break;
                                                                            }
                                                                              }
                                                         }
                                                           }

                                                         return selected;
                                                           return selected;
                                         }
                                             }
                      }
                       }
                 © Jason Gorman 2005. All rights reserved.
The OCL Collection Hierarchy
                                            Collection




                   Set                         Bag                                 Sequence




Elements can be included only    Elements can be included                      Elements can be included
once, and in no specific order   more than once, in no                         more than once, but in a
                                 specific order                                specific order




                                   © Jason Gorman 2005. All rights reserved.
Operations on All Collections
Operation                 Description
size                      The number of elements in the collection
count(object)             The number of occurences of object in the collection.
includes(object)          True if the object is an element of the collection.
includesAll(collection)   True if all elements of the parameter collection are present in the current collection.


isEmpty                   True if the collection contains no elements.
notEmpty                  True if the collection contains one or more elements.
iterate(expression)       Expression is evaluated for every element in the collection.
sum(collection)           The addition of all elements in the collection.
exists(expression)        True if expression is true for at least one element in the collection.


forAll(expression)        True if expression is true for all elements.
select(expression)        Returns the subset of elements that satisfy the expression
reject(expression)        Returns the subset of elements that do not satisfy the expression


collect(expression)       Collects all of the elements given by expression into a new collection


one(expression)           Returns true if exactly one element satisfies the expression


sortedBy(expression)      Returns a Sequence of all the elements in the collection in the order specified (expression must
                          contain the < operator


                                     © Jason Gorman 2005. All rights reserved.
Examples of Collection Operations

    account1 : Account
                             accounts
  id = 2543
  balance = 450                                       holder

                                                                   jason : Customer      holder


                                                                holder                                        accounts
       account2 : Account

     id = 4569                                                                                       account4 : Account
                                accounts
     balance = 100
                                                                                                   id = 5613
                                                             accounts
                                                                                                   balance = 50
                                              account3 : Account

                                            id = 4288
                                            balance = 250


                                                                                             bool forAll = true;
                                                                                               bool forAll = true;
jason.accounts->forAll(a : Account | a.balance > 0) = true
                                                                                             foreach(Account a in accounts)
                                                                                               foreach(Account a in accounts)
jason.accounts->select(balance > 100) = {account1, account3}                                 {
                                                                                               {
                                                                                                       if(!(a.balance > 0))
jason.accounts->includes(account4) = true                                                                if(!(a.balance > 0))
                                                                                                      {
                                                                                                        {
jason.accounts->exists(a : account | a.id = 333) = false
                                                                                                                 forAll = forAll && (a.balance > 0);
                                                                                                                   forAll = forAll && (a.balance > 0);
jason.accounts->includesAll({account1, account2}) = true                                               }
                                                                                                         }
                                                                                             }
jason.accounts.balance->sum() = 850                                                            }

Jason.accounts->collect(balance) = {450, 100, 250, 50}


                                             © Jason Gorman 2005. All rights reserved.
Navigating Across & Flattening Collections

  account1 : Account
                         accounts
id = 2543                                                                                                tsb : Bank
balance = 450                                     holder

                                                             jason : Customer        customers


    account2 : Account
                                                                                                 customers
  id = 4569
                           accounts
  balance = 100                                                          holder      antony : Customer

                                                                                              holder




                                                                                          accounts

                                                                             account4 : Account
                                            accounts
                                                                          id = 5613
                           account3 : Account                             balance = 50
                         id = 4288
                         balance = 250




                  tsb.customers.accounts = {account1, account2, account3, account}
                  tsb.customers.accounts.balance = {450, 100, 250, 50}


                                         © Jason Gorman 2005. All rights reserved.
Specialized Collection Operations
                                              Collection




                Set                              Bag                                         Sequence

minus(Set) : Set                      union(Bag) : bag                           first() : OclAny
union(Set) : Set                      union(Set) : bag                           last() : OclAny
union(Bag) : Bag                      intersection(Set) : Set                    at(Integer) : OclAny
symettricDifference(Set) : Set        intersection(Bag) : Bag                    append(OclAny)
intersection(Set) : Set               including(OclAny) : Bag                    prepend(OclAny)
intersection(Bag) : Set               excluding(OclAny) : Bag                    including(OclAny) : Sequence
including(OclAny) : Set               asSet() : Set                              excluding(OclAny) : Sequence
excluding(OclAny) : Set               asSequence() : Sequence                    asBag() : Bag
asBag() : Bag                                                                    asSet() : Set
asSequence() : Sequence


                                 Eg, Set{4, 2, 3, 1}.minus(Set{2, 3}) = Set{4, 1}
                                 Eg, Bag{1, 2, 3, 5}.including(6) = Bag{1, 2, 3, 5, 6}
                                 Eg, Sequence{1, 2, 3, 4}.append(5) = Sequence{1, 2, 3, 4, 5}




                                     © Jason Gorman 2005. All rights reserved.
Navigating across Qualified
       Associations

                                           holder
                 account
       Account                              id              Customer
                 0..1
                                                 1
balance : Real
id : Integer




       customer.account[3435]

       Or

       customer.account[id = 3435]


                        © Jason Gorman 2005. All rights reserved.
Navigating to Association
             Classes
A                                       B




                    C                                          x
                                                                                          C

                                                                   A
                                                                           y

    context A inv: self.c

    context B inv: self.c
                                                               context A inv: self.c[x]

                                                               context A inv: self.c[y]




                            © Jason Gorman 2005. All rights reserved.
Equivalents to Association
             Classes
      c       c
A         C                   B




                                                                  c
                                                                      C


                                                                          c
                                                         x

                                                              A
                                                                  y




                  © Jason Gorman 2005. All rights reserved.
Built-in OCL Types : OclType
                                                                                      Party




                                                                             Person               Organisation




                                 accounts                 holder
               Account                                                     Customer
                                 *                            1
       balance : Real
       id : Integer



             OclType                          Eg, Account.name() = “Account”
name() : String
attributes() : Set(String)
                                              Eg, Account.attributes() = Set{“balance”, “id”}
associationEnds : Set(String)
operations() : Set(String)                    Eg, Customer.supertypes() = Set{Person}
supertypes() : Set(OclType)
allSupertypes() ; Set(OclType)                Eg, Customer.allSupertypes() = Set{Person, Party}
allInstances() : Set(OclAny)



                                       © Jason Gorman 2005. All rights reserved.
Built-in OCL Types : OclAny
  account1 : Account
                         accounts
id = 2543
balance = 450                                    holder

                                                              jason : Customer      holder


                                                           holder                                     accounts
    account2 : Account

  id = 4569                                                                                    account4 : Account
                            accounts
  balance = 100
                                                                                             id = 5613
                                                       accounts
                                                                                             balance = 50
                                         account3 : Account

                                       id = 4288
                                       balance = 250




             OclAny                            Eg, jason.oclType() = Customer
oclIsKindOf(OclType) : Booelan
oclIsTypeOf(OclType) : Boolean                 Eg, jason.oclIsKindOf(Person) = true
oclAsType(OclType) : OclAny
oclInState(OclState) : Boolean                 Eg, jason.oclIsTypeOf(Person) = false
oclIsNew() : Boolean
oclType() : OclType
                                               Eg, Account.allInstances() = Set{account1, account2, account3, account4}



                                        © Jason Gorman 2005. All rights reserved.
More on OCL
• OCL 1.5 Language Specification
• OCL Evaluator – a tool for editing, syntax
  checking & evaluating OCL
• Octopus OCL 2.0 Plug-in for Eclipse




                © Jason Gorman 2005. All rights reserved.
www.parlezuml.com




    © Jason Gorman 2005. All rights reserved.

More Related Content

Similar to UML for Java Developers

The Unbearable Stupidity of Modeling
The Unbearable Stupidity of ModelingThe Unbearable Stupidity of Modeling
The Unbearable Stupidity of Modelingmerks
 
Chapter 6 the modeling activity
Chapter 6   the modeling activityChapter 6   the modeling activity
Chapter 6 the modeling activityarief_rudyanto
 
Applying Aspect-Extended UML Modelling to 'e'
Applying Aspect-Extended UML Modelling to 'e'Applying Aspect-Extended UML Modelling to 'e'
Applying Aspect-Extended UML Modelling to 'e'DVClub
 
Darren galpin q4_2008_bristol
Darren galpin q4_2008_bristolDarren galpin q4_2008_bristol
Darren galpin q4_2008_bristolObsidian Software
 
UML with Action Semantics
UML with Action SemanticsUML with Action Semantics
UML with Action Semanticselliando dias
 
UML Generator (NCC18)
UML Generator (NCC18)UML Generator (NCC18)
UML Generator (NCC18)IT Industry
 
4 - Overview of Generative AI Session#4.pptx
4 - Overview of Generative AI Session#4.pptx4 - Overview of Generative AI Session#4.pptx
4 - Overview of Generative AI Session#4.pptxSumathy
 
Моделирование бизнес-процессов на UML
Моделирование бизнес-процессов на UMLМоделирование бизнес-процессов на UML
Моделирование бизнес-процессов на UMLOlya Kollen, PhD
 
Journey To The Front End World - Part3 - The Machine
Journey To The Front End World - Part3 - The MachineJourney To The Front End World - Part3 - The Machine
Journey To The Front End World - Part3 - The MachineIrfan Maulana
 
The Agile Gap: Closing it with User Experience
The Agile Gap: Closing it with User ExperienceThe Agile Gap: Closing it with User Experience
The Agile Gap: Closing it with User Experiencekalebwalton
 
Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2wahab13
 
Summary of Excel Skills
Summary of Excel SkillsSummary of Excel Skills
Summary of Excel Skillsjunggi784
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Javawiradikusuma
 
O'reilly learning uml.chm
O'reilly   learning uml.chmO'reilly   learning uml.chm
O'reilly learning uml.chmlion6666
 
Preview java j2_ee_book
Preview java j2_ee_bookPreview java j2_ee_book
Preview java j2_ee_bookSubhadip Pal
 
Programming in UML: Why and How
Programming in UML: Why and HowProgramming in UML: Why and How
Programming in UML: Why and HowEd Seidewitz
 

Similar to UML for Java Developers (20)

The Unbearable Stupidity of Modeling
The Unbearable Stupidity of ModelingThe Unbearable Stupidity of Modeling
The Unbearable Stupidity of Modeling
 
Chapter 6 the modeling activity
Chapter 6   the modeling activityChapter 6   the modeling activity
Chapter 6 the modeling activity
 
Applying Aspect-Extended UML Modelling to 'e'
Applying Aspect-Extended UML Modelling to 'e'Applying Aspect-Extended UML Modelling to 'e'
Applying Aspect-Extended UML Modelling to 'e'
 
Darren galpin q4_2008_bristol
Darren galpin q4_2008_bristolDarren galpin q4_2008_bristol
Darren galpin q4_2008_bristol
 
UML Design.pptx
UML Design.pptxUML Design.pptx
UML Design.pptx
 
UML with Action Semantics
UML with Action SemanticsUML with Action Semantics
UML with Action Semantics
 
DISE - OOAD Using UML
DISE - OOAD Using UMLDISE - OOAD Using UML
DISE - OOAD Using UML
 
UML Generator (NCC18)
UML Generator (NCC18)UML Generator (NCC18)
UML Generator (NCC18)
 
4 - Overview of Generative AI Session#4.pptx
4 - Overview of Generative AI Session#4.pptx4 - Overview of Generative AI Session#4.pptx
4 - Overview of Generative AI Session#4.pptx
 
Моделирование бизнес-процессов на UML
Моделирование бизнес-процессов на UMLМоделирование бизнес-процессов на UML
Моделирование бизнес-процессов на UML
 
Journey To The Front End World - Part3 - The Machine
Journey To The Front End World - Part3 - The MachineJourney To The Front End World - Part3 - The Machine
Journey To The Front End World - Part3 - The Machine
 
The Agile Gap: Closing it with User Experience
The Agile Gap: Closing it with User ExperienceThe Agile Gap: Closing it with User Experience
The Agile Gap: Closing it with User Experience
 
Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2
 
Summary of Excel Skills
Summary of Excel SkillsSummary of Excel Skills
Summary of Excel Skills
 
Object oriented analysis and design unit- iii
Object oriented analysis and design unit- iiiObject oriented analysis and design unit- iii
Object oriented analysis and design unit- iii
 
OOP Java
OOP JavaOOP Java
OOP Java
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Java
 
O'reilly learning uml.chm
O'reilly   learning uml.chmO'reilly   learning uml.chm
O'reilly learning uml.chm
 
Preview java j2_ee_book
Preview java j2_ee_bookPreview java j2_ee_book
Preview java j2_ee_book
 
Programming in UML: Why and How
Programming in UML: Why and HowProgramming in UML: Why and How
Programming in UML: Why and How
 

More from elliando dias

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slideselliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScriptelliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structureselliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de containerelliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Librarieselliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Webelliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduinoelliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorceryelliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Designelliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makeselliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebookelliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Studyelliando dias
 

More from elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Recently uploaded

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

UML for Java Developers

  • 1. UML for Java Developers Model Constraints & The Object Constraint Language Jason Gorman © Jason Gorman 2005. All rights reserved.
  • 2. quot;I am currently working on a team which is [in] the process of adopting RUP and UML UML for Java Developers (5 Days) standards and practices. After Since Autumn 2003, over 100,000 Java and .NET developers have one of our design sessions, I learned the Unified Modeling Language from Parlez UML needed to lookup some (http://www.parlezum l.com) , making it one of the most popular information and came across UML training resources on the Internet. your site. Absolutely great! Most [of] the information I've had questions about is UML for Java Developers is designed to accelerate the learning contained within your tutorials process by explaining UML in a language Java developers can and then some.quot; understand – Java! From Requirements to a Working System quot;Really great site... I have been Many UML courses focus on analysis and high-level design, falling trying to grasp UML since the short of explaining how you get from there to a w orking system. UML day I saw Visual Modeler. I knew a few things but there for Java Developers takes you all the w ay from system were gaps. Thanks to your site requirements to the finished code because that, after all, is w hy we they have shrunk model in the first place. considerably.quot; Learning By Doing UML modeling is a practical skill, like driving a car or flying a plane. quot;I went on a UML training Just as w e don’t learn to drive just by looking at Pow erPoint course three months ago, and came out with a big folder full presentations, you cannot properly learn UML w ithout getting plenty of hand-outs and no real of practice at it. understanding of UML and how to use it on my project. I spent Your skills w ill be developed by designing and building a w orking a day reading the UML for piece of software, giving you a genuine understanding of how UML .NET tutorials and it was a can be applied throughout the development lifecycle. much easier way to learn. 'Here's the diagram. Now here's the code.' Simple.quot; www.parlezuml.com/training.htm advertisement © Jason Gorman 2005. All rights reserved.
  • 3. UML for Java Developers covers the most useful aspects of the UML standard, applying each notation w ithin the context of an iterative, object oriented development process Use Case Diagrams Object Diagrams & Filmstrips Model the users of the system Model snapshots of the running and the goals they can achieve system and show how actions by using it change object state Class Diagrams Implementation Diagrams Model types of objects and Model the physical components of a the relationships between system and their deployment them. architecture Sequence Diagrams Packages & Model how objects interact Model Management to achieve functional goals Organise your logical and physical models with packages Activity Diagrams Object Constraint Language Model the flow of use cases Model business rules and create and single and multi-threaded unambiguous specifications code Statechart Diagrams User Experience Modeling Model the behaviour of objects Design user-centred systems with and event-driven applications UML Design Principles Design Patterns Create well-designed software Apply proven solutions to common that’s easier to change and OO design problems reuse www.parlezuml.com/training.htm © Jason Gorman 2005. All rights reserved.
  • 4. UML Diagrams Don’t Tell Us Everything children parents 0..2 parents valid instance of Bill : Person parents * Person children children © Jason Gorman 2005. All rights reserved.
  • 5. Constraints Make Models More Precise children parents 0..2 parents not a valid instance of Bill : Person parents * Person children children {cannot be own descendant or ancestor } © Jason Gorman 2005. All rights reserved.
  • 6. What is the Object Constraint Language? • A language for expressing necessary extra information about a model • A precise and unambiguous language that can be read and understood by developers and customers • A language that is purely declarative – ie, it has no side-effects (in other words it describes what rather than how) © Jason Gorman 2005. All rights reserved.
  • 7. What is an OCL Constraint? • An OCL constraint is an OCL expression that evaluates to true or false (a Boolean OCL expression, in other words) © Jason Gorman 2005. All rights reserved.
  • 8. OCL Makes Constraints Unambiguous {ancestors = parents->union(parents.ancestors->asSet())} {descendants = children->union(children.descendants->asSet()) parents 0..2 ancestors * Person * children * descendants /family tree {ancestors->excludes(self) and descendants->excludes(self) } © Jason Gorman 2005. All rights reserved.
  • 9. Introducing OCL – Constraints & Contexts {ancestors = parents->union(parents.ancestors->asSet())} {descendants = children->union(children.descendants->asSet()) parents 0..2 ancestors * Person Q: To what which type this constraint apply? * children A: Person * descendants /family tree context Person context Person inv: ancestors->excludes(self) and descendants->excludes(self) inv: ancestors->excludes(self) and descendants->excludes(self) Q: When does this constraint apply? {ancestors->excludes(self) and descendants->excludes(self) } A: inv = invariant = always © Jason Gorman 2005. All rights reserved.
  • 10. Operations, Pre & Post- conditions <<enumeration>> Sex MALE = 1 FEMALE = 2 Person 0..1 sex : Sex optional constraint name spouse marry(p : Person) applies to the marry() operation of the type Person context Person::marry(p : Person) context Person::marry(p : Person) pre cannot_marry_self: not (p = self) pre cannot_marry_self: not (p = self) pre not_same_sex: not (p.sex = self.sex) comments start with -- pre not_same_sex: not (p.sex = self.sex) -- neither person can be married already -- neither person can be married already pre not_already_married: self.spouse->size() = 0 and p.spouse->size() = 0 pre not_already_married: self.spouse->size() = 0 and p.spouse->size() = 0 post : self.spouse = p and p.spouse = self post : self.spouse = p and p.spouse = self © Jason Gorman 2005. All rights reserved.
  • 11. Design By Contract :assert class Sex class Sex { { static final int MALE = 1; static final int MALE = 1; static final int FEMALE = 2; static final int FEMALE = 2; } } class Person class Person { { public int sex; public int sex; public Person spouse; public Person spouse; self public void marry(Person p) public void marry(Person p) { { assert p != this; assert p != this; context Person::marry(p : Person) context Person::marry(p : Person) assert p.sex != this.sex; pre cannot_marry_self: not (p = self) assert p.sex != this.sex; pre cannot_marry_self: not (p = self) pre not_same_sex: not (p.sex = self.sex) assert this.spouse = null && p.spouse = null; pre not_same_sex: not (p.sex = self.sex) assert this.spouse = null && p.spouse = null; -- neither person can be married a lready -- neither person can be married a lready pre not_already_married: self.spouse->size() = 0 and p.spouse->size() = 0 pre not_already_married: self.spouse->size() = 0 and p.spouse->size() = 0 post : self.spouse = p and p.spouse = self this.spouse = p; post : self.spouse = p and p.spouse = self this.spouse = p; p.spouse = this; p.spouse = this; } self.spouse->size = 0 } } } © Jason Gorman 2005. All rights reserved.
  • 12. Defensive Programming : Throwing Exceptions class Person class Person { { public int sex; public int sex; public Person spouse; public Person spouse; public void marry(Person p) throws ArgumentException { public void marry(Person p) throws ArgumentException { if(p == this) { if(p == this) { throw new ArgumentException(quot;cannot marry selfquot;); throw new ArgumentException(quot;cannot marry selfquot;); } } if(p.sex == this.sex) { if(p.sex == this.sex) { throw new ArgumentException(quot;spouse is sa me sexquot;); throw new ArgumentException(quot;spouse is sa me sexquot;); } } if((p.spouse != null || this.spouse != null) { if((p.spouse != null || this.spouse != null) { throw new ArgumentException(quot;already marriedquot;); throw new ArgumentException(quot;already marriedquot;); } } this.spouse = p; this.spouse = p; p.spouse = this; p.spouse = this; } } } } © Jason Gorman 2005. All rights reserved.
  • 13. Referring to previous values and operation return values Account balance : Real = 0 deposit(amount : Real) withdraw(a mount : Real) balance before execution of operation getBalance() : Real context Account::withdraw (amount : Real) context Account::withdraw (amount : Real) pre: amount <= balance pre: amount <= balance post: balance = balance@pre - amount post: balance = balance@pre - amount context Account::getBalance() : Real context Account::getBalance() : Real post : result = balance post : result = balance return value of operation © Jason Gorman 2005. All rights reserved.
  • 14. @pre and result in Java class Account class Account { { private float balance = 0; context Account::withdraw(amount : Real) private float balance = 0; context Account::withdraw(amount : Real) pre: amount <= balance pre: amount <= balance post: balance = balance@pre - amount public void withdraw(float amount) { post: balance = balance@pre - amount public void withdraw(float amount) { assert amount <= balance; context Account::getBalance() : Real assert amount <= balance; context Account::getBalance() : Real post : result = balance post : result = balance balance = balance - a mount; balance = balance - a mount; } } public void testWithdrawWithSufficientFunds() { Account account = new Account(); public void deposit(float a mount) { public void deposit(float a mount) { balance = balance + a mount; balance = balance + a mount; account.deposit(500); } } float balanceAtPre = account.getBalance(); public float getBalance() { public float getBalance() { return balance; return balance; float amount = 250; } result = balance } } } account.withdraw(amount); assertTrue(account.getBalance() == balanceAtPre – a mount); } balance = balance@pre - amount © Jason Gorman 2005. All rights reserved.
  • 15. OCL Basic Value Types Account • Integer : A whole number of any size balance : Real = 0 name : String • Real : A decimal number of any size id : Integer isActive : Boolean • String : A string of characters deposit(amount : Real) withdraw(a mount : Real) • Boolean : True/False id : Integer balance : Real = 0 name : String isActive : Boolean int id; double balance = 0; string na me; boolean isActive; long id; float balance = 0; char[] na me; byte id; short id; © Jason Gorman 2005. All rights reserved.
  • 16. Operations on Real and Integer Types Operation Notation Result type equals a =b Boolean not equals a <> b Boolean less a <b Boolean more a >b Boolean less or equal a <= b Boolean more or equal a >= b Boolean plus a +b Integer or Real minus a -b Integer or Real multiply a*b Integer or Real divide a /b Real modulus a.mod(b) Integer integer division a.div(b) Integer absolute value a.abs Integer or Real maximum a.max(b) Integer or Real minimum a.min(b) Integer or Real round a.round Integer floor a.floor Integer Eg, 6.7.floor() = 6 © Jason Gorman 2005. All rights reserved.
  • 17. Operations on String Type Operation Expression Result type concatenation s.concat(string) String size s.size Integer to lower case s.toLower String to upper case s.toUpper String substring s.substring(int, int) String equals s1 = s2 Boolean not equals s1 <> s2 Boolean Eg, ‘jason’.concat(‘ gorman’) = ‘jason gorman’ Eg, ‘jason’.substring(1, 2) = ‘ja’ © Jason Gorman 2005. All rights reserved.
  • 18. Operations on Boolean Type Operation Notation Result type or a or b Boolean and a and b Boolean exclusive or a xor b Boolean negation not a Boolean equals a=b Boolean not equals a <> b Boolean implication a implies b Boolean if then else if a then b1 else b2 endif type of b Eg, true or false = true Eg, true and false = false © Jason Gorman 2005. All rights reserved.
  • 19. Navigating in OCL Expressions accounts holder Account Customer * 1 In OCL: account.holder Evaluates to a customer object who is in the role holder for that association And: customer.accounts Evaluates to a collection of Account objects in the role accounts for that association Account account = new Account(); Account account = new Account(); Customer customer = new Customer(); Customer customer = new Customer(); customer.accounts = new Account[] {account}; customer.accounts = new Account[] {account}; account.holder = customer; account.holder = customer; © Jason Gorman 2005. All rights reserved.
  • 20. Navigability in OCL Expressions b A B 1 a.b is allowed b.a is not allowed – it is not navigable class A class A { { public B b; public B b; } } class B class B { { } } © Jason Gorman 2005. All rights reserved.
  • 21. Calling class features Account id : Integer status : enum{active, frozen, closed} balance : Real nextId : Integer deposit(amount : Real) context Account::createNew() : Account context Account::createNew() : Account withdraw(a mount : Real) post: result.oclIsNew() and fetch(id : Integer) : Account post: result.oclIsNew() and result.id = Account.nextId@pre and result.id = Account.nextId@pre and Account.nextId = result.id + 1 Account.nextId = result.id + 1 © Jason Gorman 2005. All rights reserved.
  • 22. Enumerations in OCL Account context Account::withdraw(amount : Real) context Account::withdraw(amount : Real) balance : Real pre: amount <= balance pre: amount <= balance deposit(amount : Real) pre: status = AccountStatusKind.ACT IVE pre: status = AccountStatusKind.ACT IVE withdraw(a mount : Real) post: balance = balance@pre - amount post: balance = balance@pre - amount 1 status <<enumeration>> AccountStatusKind ACTIVE FROZEN CLOSED © Jason Gorman 2005. All rights reserved.
  • 23. Collections in OCL accounts holder Account Customer * 1 balance : Real id : Integer customer.accounts.balance = 0 is not allowed customer.accounts->select(id = 2324).balance = 0 is allowed © Jason Gorman 2005. All rights reserved.
  • 24. class Account class Account Collections in { { public double balance; public double balance; public int id; public int id; Java } } class Customer class Customer { { Account[] accounts; Account[] accounts; public Account SelectAccount(int id) public Account SelectAccount(int id) { { Account selected = null; Account selected = null; for(int i = 0; i < accounts.length; i++) for(int i = 0; i < accounts.length; i++) { { Account account = accounts[i]; Account account = accounts[i]; if(account.id = id) if(account.id = id) { { selected = account; selected = account; break; break; } } } } return selected; return selected; } } } } © Jason Gorman 2005. All rights reserved.
  • 25. The OCL Collection Hierarchy Collection Set Bag Sequence Elements can be included only Elements can be included Elements can be included once, and in no specific order more than once, in no more than once, but in a specific order specific order © Jason Gorman 2005. All rights reserved.
  • 26. Operations on All Collections Operation Description size The number of elements in the collection count(object) The number of occurences of object in the collection. includes(object) True if the object is an element of the collection. includesAll(collection) True if all elements of the parameter collection are present in the current collection. isEmpty True if the collection contains no elements. notEmpty True if the collection contains one or more elements. iterate(expression) Expression is evaluated for every element in the collection. sum(collection) The addition of all elements in the collection. exists(expression) True if expression is true for at least one element in the collection. forAll(expression) True if expression is true for all elements. select(expression) Returns the subset of elements that satisfy the expression reject(expression) Returns the subset of elements that do not satisfy the expression collect(expression) Collects all of the elements given by expression into a new collection one(expression) Returns true if exactly one element satisfies the expression sortedBy(expression) Returns a Sequence of all the elements in the collection in the order specified (expression must contain the < operator © Jason Gorman 2005. All rights reserved.
  • 27. Examples of Collection Operations account1 : Account accounts id = 2543 balance = 450 holder jason : Customer holder holder accounts account2 : Account id = 4569 account4 : Account accounts balance = 100 id = 5613 accounts balance = 50 account3 : Account id = 4288 balance = 250 bool forAll = true; bool forAll = true; jason.accounts->forAll(a : Account | a.balance > 0) = true foreach(Account a in accounts) foreach(Account a in accounts) jason.accounts->select(balance > 100) = {account1, account3} { { if(!(a.balance > 0)) jason.accounts->includes(account4) = true if(!(a.balance > 0)) { { jason.accounts->exists(a : account | a.id = 333) = false forAll = forAll && (a.balance > 0); forAll = forAll && (a.balance > 0); jason.accounts->includesAll({account1, account2}) = true } } } jason.accounts.balance->sum() = 850 } Jason.accounts->collect(balance) = {450, 100, 250, 50} © Jason Gorman 2005. All rights reserved.
  • 28. Navigating Across & Flattening Collections account1 : Account accounts id = 2543 tsb : Bank balance = 450 holder jason : Customer customers account2 : Account customers id = 4569 accounts balance = 100 holder antony : Customer holder accounts account4 : Account accounts id = 5613 account3 : Account balance = 50 id = 4288 balance = 250 tsb.customers.accounts = {account1, account2, account3, account} tsb.customers.accounts.balance = {450, 100, 250, 50} © Jason Gorman 2005. All rights reserved.
  • 29. Specialized Collection Operations Collection Set Bag Sequence minus(Set) : Set union(Bag) : bag first() : OclAny union(Set) : Set union(Set) : bag last() : OclAny union(Bag) : Bag intersection(Set) : Set at(Integer) : OclAny symettricDifference(Set) : Set intersection(Bag) : Bag append(OclAny) intersection(Set) : Set including(OclAny) : Bag prepend(OclAny) intersection(Bag) : Set excluding(OclAny) : Bag including(OclAny) : Sequence including(OclAny) : Set asSet() : Set excluding(OclAny) : Sequence excluding(OclAny) : Set asSequence() : Sequence asBag() : Bag asBag() : Bag asSet() : Set asSequence() : Sequence Eg, Set{4, 2, 3, 1}.minus(Set{2, 3}) = Set{4, 1} Eg, Bag{1, 2, 3, 5}.including(6) = Bag{1, 2, 3, 5, 6} Eg, Sequence{1, 2, 3, 4}.append(5) = Sequence{1, 2, 3, 4, 5} © Jason Gorman 2005. All rights reserved.
  • 30. Navigating across Qualified Associations holder account Account id Customer 0..1 1 balance : Real id : Integer customer.account[3435] Or customer.account[id = 3435] © Jason Gorman 2005. All rights reserved.
  • 31. Navigating to Association Classes A B C x C A y context A inv: self.c context B inv: self.c context A inv: self.c[x] context A inv: self.c[y] © Jason Gorman 2005. All rights reserved.
  • 32. Equivalents to Association Classes c c A C B c C c x A y © Jason Gorman 2005. All rights reserved.
  • 33. Built-in OCL Types : OclType Party Person Organisation accounts holder Account Customer * 1 balance : Real id : Integer OclType Eg, Account.name() = “Account” name() : String attributes() : Set(String) Eg, Account.attributes() = Set{“balance”, “id”} associationEnds : Set(String) operations() : Set(String) Eg, Customer.supertypes() = Set{Person} supertypes() : Set(OclType) allSupertypes() ; Set(OclType) Eg, Customer.allSupertypes() = Set{Person, Party} allInstances() : Set(OclAny) © Jason Gorman 2005. All rights reserved.
  • 34. Built-in OCL Types : OclAny account1 : Account accounts id = 2543 balance = 450 holder jason : Customer holder holder accounts account2 : Account id = 4569 account4 : Account accounts balance = 100 id = 5613 accounts balance = 50 account3 : Account id = 4288 balance = 250 OclAny Eg, jason.oclType() = Customer oclIsKindOf(OclType) : Booelan oclIsTypeOf(OclType) : Boolean Eg, jason.oclIsKindOf(Person) = true oclAsType(OclType) : OclAny oclInState(OclState) : Boolean Eg, jason.oclIsTypeOf(Person) = false oclIsNew() : Boolean oclType() : OclType Eg, Account.allInstances() = Set{account1, account2, account3, account4} © Jason Gorman 2005. All rights reserved.
  • 35. More on OCL • OCL 1.5 Language Specification • OCL Evaluator – a tool for editing, syntax checking & evaluating OCL • Octopus OCL 2.0 Plug-in for Eclipse © Jason Gorman 2005. All rights reserved.
  • 36. www.parlezuml.com © Jason Gorman 2005. All rights reserved.