Title: CS551 Static Models: Object Attributes and Invariants Chap' 2 of UML
1CS551 Static Models Object Attributes
and Invariants (Chap. 2 of UML)
- Yugi Lee
- STB 555
- (816) 235-5932
- yugi_at_cstp.umkc.edu
- www.cstp.umkc.edu/yugi
2Object Modelling
- Static model the state of an object at any given
moment (object attributes, relationships,
constraints between objects) - Dynamic model the changes that happen to the
state as event occur (actions affect objects,
using the changes of objects and attributes in
the object state) - Interactive model interactions between objects
(the responsibility for achieving goal is divided
among collaborating objects)
3(No Transcript)
4Modeling Objects Definitions
- Type a collection of objects with similar
behaviors, satisfying the specification of that
type - Type model Behaviors are specified in terms of
attributes, a valid abstract model of many
possible implementations. - Action is described in terms of its effect on the
attributes of the participating objects and the
output it produces. - Abstract interaction joint actions and
collaboration specific interactions as
refinements of more abstract interactions.
5(No Transcript)
6Type Class
- A class is a programming implementation unit
- for all instances of that class, it defines the
procedural methods and data stored as instance
variables. - Each method read and modify the instance
variables of that instance, communicate with
other objects referred to via those instance
variables or passed in as parameters to the
method. - A type is a modeling and specification construct
applicable to OO code. - Is abstracts algorithmic or procedural behaviors
with specifications of actions and abstracts
data or information representation by attributes. - Every method implementation must meet the net
result specified by the action specification and
the stored data must represent enough information
in some form so that every attribute can be
determined from that representation.
7Type Class
- A class implements some (number of) types(s).
Each type can be implemented by some (number of)
class(es). - For example, a class Product may implement the
type Sellable, by providing methods for each
operation defined on Sellable, and a particular
set of stored instance variables to represent the
abstract state required by that type. Another
class Service can also implement Sellable, with
very different implementations of its methods and
different instance variables to represent the
sale of services. - The same class Product can also implement a
different type ReStockable the class Service is
not likely to implement this type.
8Example Type and Class
Product ltltclassgt
implement
op1() op5() op7() op9()
implement
Service ltltclassgtgt
op1() .
implement
9Type Class
- One type can be defined as an extension of
another i.e. as a subtype of another. The subtype
has at least all the attributes and action
specifications that the supertype has. - One class can have its implementation defined as
an extension or modification of another class.
The subclass inherits all instance variables and
methods from the superclass. It may add more
instance variables and methods, and can override
selected methods implementations from its
superclass with its own. - An abstract class is a partial implementation
unit it cannot be instantiated on its own as it
has certain pieces missing (typically, method
implementations) that need to be filled in by a
subclass.
10(No Transcript)
11Intermediate Modeling State
- The state of an object - information that can be
associated with it at any given point in time
(individual identity, characteristic behavior,
and state (a combination of stored state and
executable code))- is modeled by a static model
on a type that describes that object. - The static model consists of a set of attributes
- properties that define information on the state
of the object at any point in time and a set of
static invariants - rules on what combinations of
attribute values are valid for that object's
state to be valid. - For example, the static model of an Order may
include attributes for a set of LineItems (each,
in turn, for some quantity of a product), the
orderTotal, and the Customer. The static
invariants on Order may include rules like "no
two LineItems can be for the same Product", or
"the orderTotal cannot be greater than the
customer's credit limit".
12Modeling Objet State Attribute
- A convenience attribute
- describe things without it by referring to some
more basic attributes, - simplifies what you need to say and may provide
some de-coupling from the more detailed
attributes. - has a static invariant that defines its value in
terms of other attributes. - e.g., you may not strictly need to define
orderTotal as an attribute, since you could
simply refer to the quantity of each of its line
items, and the unit price of the corresponding
product, with equivalent effect. - However, introducing orderTotal simplifies your
descriptions of other activities such as
invoicing and payment, de-couples those
descriptions from changes in the way the order
total is determined, and reduces duplication. - We would need to add a static invariant which
said the orderTotal is the same as the sum of
each LineItem's quantity times that product's
unit price.
13Modeling Object State Association
- An association graphically depicts an inverse
pair of attributes. - For example, the customer attribute of an Order,
and the setOfOrders attribute of a Customer could
be defined as a single association between the
two object types.
order
Order
Customer
14(No Transcript)
15Modeling Object State Snapshot and filmstrip
- A snapshot shows a set of objects and their
configuration at a point in time (the values of
their attributes or links to other objects). - A filmstrip shows a sequence of snapshots
evolving through the steps of a scenario.
16Modeling Object State Types, Attributes and
Associations
- Attributes model and realityan attribute need
not correspond directly to stored data in an
implementation - Parameterized attribute its value is a function
from a list of parameters to an object identity - session-5.startDate.isLessThan (today)
- session-5.startDate lt today
- Association a pair of attributes that are
inverses of each other, drawn as a line joining
the two types on a type model.
17Modeling Object State Types, Attributes and
Associations
- Collections many attributes have that are
collections of other objects. - Set a collection of objects without any
duplicates) - Bag a collection with duplicates of elements
- Seq a sequence-a bag with an ordering of its
elements. - Operators
- dot (.) operator for a collection evaluates an
attribute on every element of the collection and
returns another collection - e.g., clients.sessions Set s1, s5, s9
- The -gt operator for a collection evaluates an
attribute on the collection itself rather than on
each of its elements - e.g., client3.sessions -gt count 3
18Modeling Object State Types, Attributes and
Associations
- forAll, exists
- //every one of lauras session grades is better
than pass. - laura.sessions.grade -gt forAll (gg.betterThan(Gra
de.pass)) - //at least one of lauras session grades is a
Grade A - laura.sessions.grade-gt exists(ggGrade.A)
- union (), intersection (), difference (-)
- laura.sessions.course marty.sessions.course
//the courses taught by either - laura.sessions.course marty.sessions.course
//the courses taught by both - laura.session.course - marty.sessions.course
- //the course taught by Laura that are not
taught by Marty
19Static Invariants
- Static invariant a predicate, forming part of a
type model, that should hold true on every
permitted snapshot-specifically, before and after
every action in the model. - Inv instructor qualifiedFor -gt includesAll
(sections.course) - inv instructor sessions.course lt qualifiedFor
- Boolean Operators an invariant is a Boolean
expression Quantifier (forall, exists) - and (), or (), a implies b (a gt b), not a
(!a), - aSet -gt forall (xP(x)) is equivalent to
xaSetP(x), - aSet -gt exists (xP(x)) is equivalent to exist
xaSet, P(x) - Context Operator() short for an explicit
forall - // a session has an evaluation exactly when it is
completed. - inv Sessionself.completed (self.eval ltgt null)
- inv Session -gt forall (self self.completed
(self.eval ltgt null))
20Boolean Operators
21(No Transcript)
22Static Invariants
- Invariants in code
- boolean assignQualified ()
- for (Enumeration e session.elements()
e.hasMoreElements) - Course course ((Session) e.nextElement
()).course() - if(! qualifiedForCourses.contains (course))
- return false
-
- return ture
23Static Invariants Common Uses
- Derived attributes the value of one attribute
can be fully determined by other attributes - e.g., //clients taught clients of past sessions
I have taught - inv InstructorClientsTaught sessionsdate lt
today.client - Derived parameterized attributes
- e.g., // for every client the balance due for
that client on any date is the sum of the fees
for all sessions in the preceding 30 days - inv ClientbalanceDueOn (d Date)
- sessionsday ltd and dgt d -
30.fees -gt sum
24Static Invariants Common Uses
- Subset constraints the object linked via one
attribute must be in the set of those linked via
another attribute - e.g., //my assigned instructor must be one of my
qualified candidates - inv Sessioncandidates-gt
includes(instructor)
25Static Invariants Common Uses
- Subtype constraints a supertype can introduce
attributes that apply to several types each
subtype imposes constraints on the attributes. - State-specific constraints being in a specific
state may imply constraints on some other
attributes of an object. - Inv Session confirmed implies instructor ltgt
null - Association constraints subset (between many
associations or a 1 and a many association)
redefines (between association of subtype and
supertype)
26Dictionary
- The collected set of definitions of modeling
constructs. - The definitions must include
- the formal modeling and specification bits
(relating the formal names and symbols to each
other) - the (usually informal) description that relate
the symbols and names to things in the problem
domain. - Dictionary definitions are scoped according to
package scope rules.
27A Typical Dictionary
28Static Model Summary
- Describes the state of the business or the
component(s) we are interested in, with a set of
attributes, together with an invariant,
constitutes the static part of a type model. - each concept is described with a type
- its state is described with attributes and
associations - The invariant express constraints on the state
combinations of values that should always be
observed. - To provide a vocabulary in which to describe
actions, which include interactions in a
business, between user and software, or between
objects inside the software. - Snapshots are used to represent specific
situations, and helps to develop the static model.