Docsity

Avoiding Having Instances Change Class - Banking - Lecture Slides, Slides of Banking and Finance

Partial preview of the text

Download Avoiding Having Instances Change Class - Banking - Lecture Slides and more Slides Banking and Finance in PDF only on Docsity!

Avoiding having instances change class

  • An instance should never need to change class

5.5 Object Diagrams

  • A link is an instance of an association —In the same way that we say an object is an instance of a class

5.6 More Advanced Features: Aggregation

  • Aggregations are special associations that represent ‘part-whole’ relationships. —The ‘whole’ side is often called the assembly or the aggregate —This symbol is a shorthand notation association named isPartOf

When to use an aggregation

As a general rule, you can mark an association as an aggregation if the following are true:

  • You can state that —the parts ‘are part of’ the aggregate —or the aggregate ‘is composed of’ the parts
  • When something owns or controls the aggregate, then they also own or control the parts

Aggregation hierarchy

Propagation

  • A mechanism where an operation in an aggregate is implemented by having the aggregate perform that operation on its parts
  • At the same time, properties of the parts are often propagated back to the aggregate
  • Propagation is to aggregation as inheritance is to generalization. —The major difference is: - inheritance is an implicit mechanism - propagation has to be programmed when required

Notes and descriptive text

  • Descriptive text and other diagrams —Embed your diagrams in a larger document —Text can explain aspects of the system using any notation you like —Highlight and expand on important features, and give rationale
  • Notes : —A note is a small block of text embedded in a UML diagram —It acts like a comment in a programming language

5.7 Object Constraint Language (OCL)

OCL is a specification language designed to formally specify constraints in software modules

  • An OCL expression simply specifies a logical fact (a constraint) about the system that must remain true
  • A constraint cannot have any side-effects —it cannot compute a non-Boolean result nor modify any data.
  • OCL statements in class diagrams can specify what the values of attributes and associations must be

An example: constraints on Polygons

5.8 Detailed Example: A Class Diagram for

Genealogy

  • Problems —A person must have two parents —Marriages not properly accounted for

5.9 The Process of Developing Class

Diagrams

You can create UML models at different stages and with different purposes and levels of details

  • Exploratory domain model : —Developed in domain analysis to learn about the domain
  • System domain model : —Models aspects of the domain represented by the system
  • System model : —Includes also classes used to build the user interface and system architecture

System domain model vs System model

Suggested sequence of activities

  • Identify a first set of candidate classes
  • Add associations and attributes
  • Find generalizations
  • List the main responsibilities of each class
  • Decide on specific operations
  • Iterate over the entire process until the model is satisfactory —Add or delete classes, associations, attributes, generalizations, responsibilities or operations —Identify interfaces —Apply design patterns (Chapter 6) Don’t be too disorganized. Don’t be too rigid either.

Identifying classes

  • When developing a domain model you tend to discover classes
  • When you work on the user interface or the system architecture, you tend to invent classes —Needed to solve a particular design problem —(Inventing may also occur when creating a domain model)
  • Reuse should always be a concern —Frameworks —System extensions —Similar systems