enumerations multiplicity scope visibility · enumeration data type - a set of values together with...

28
Advanced object and class concepts Enumerations Multiplicity Scope Visibility

Upload: others

Post on 05-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Advanced object and class concepts

Enumerations

Multiplicity

Scope

Visibility

Page 2: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Enumeration Data type - a set of values together with a set of operations on those

values

To define a new simple data type, called enumeration type, we need 2 things:

A name for the data type

A set of values for the data type

enum {FALSE, TRUE};enum rank {TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT,

NINE, TEN, JACK, QUEEN, KING, ACE};enum colors {BLACK, BLUE, GREEN, CYAN, RED};

The values are written in all caps because they are constants

Page 3: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

EnumerationsWhen constructing a model, we should carefully note enumerations,

because they often occur and are important to users.

Enumerations are also significant for an implementation; we may display the possible values with a pick list.

Do not use a generalization to capture the values of an Enumerated attribute.

An Enumeration is merely a list of values; generalization is a means for structuring the description of objects.

Page 4: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

ScopeScopeUML specifies two types of scope for members: instance and classifier.

Classifier members are commonly recognized as “static” in many programming languages. The scope is the class itself.Attribute values are equal for all instancesMethod invocation does not affect the instance’s state

Instance members are scoped to a specific instance.Attribute values may vary between instancesMethod invocation may affect the instance’s state (i.e., change

instance’s attributes)To indicate a classifier scope for a member, its name must be underlined.

Otherwise, instance scope is assumed by default.

Page 5: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

11

Scope

Individual member data (attributes) may have either class scope or instance scope.

Class scope - A single copy of an attribute is shared by all instances of a class. In UML you underline the attribute to indicate class scope:

productCount : int

Instance scope - Each instance of a class would have its own copy of the attribute. All attributes have instance scope by default.

Page 6: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Visibility

Visibility refers to the ability of a method to reference a feature from another class and has the possible values of public, protected & private.

Public—Visible anywhere that the class in which it appears is visible; denoted by +.

Package—Visible anywhere in the package containing the class in which it appears; denoted by ~.

Protected—Visible in the class in which it appears and all its sub-classes; denoted by #.

Private—Visible only in the class in which it appears; denoted by -

Restricting visibility is the same as restricting accessibility.

Page 7: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

VisibilityThe UML denotes visibility with a prefix

“+” public

“-” private

“#” protected

“~” package

Page 8: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

An n-ary association is like a common (binary) association, except that more than two association roles involved in it.

The UML symbol for n-ary associations is a diamond with lines connecting to related classes. If the association has a name, it is written in italics next to the diamond.

N-ary Association

Class1 Class2

Class3

N-aryassociation

Ternaryassociation

Page 9: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

N-ary Associations

Associations can connect more than one classNotation:

Student Advisor

Major

Page 10: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

N-ary Associations

datetrainNo

TraincarriageNo

seatNo

Seat

nametitle

Passenger

Reservation

1 1..*

1..*

Page 11: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

N-ary Associations

We may occasionally encounter n-ary associations (association among 3 or more classes).

But we should try to avoid n-ary associations- most of them can be decomposed into binary associations, with possible qualifiers and attributes.

Page 12: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

20

N-ary Association

Page 13: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

21

N-ary Association (cont’d)

decompose

Page 14: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

22

AggregationA special form of association that models a whole-part relationship between

an aggregate (the whole) and its parts.Models a “is a part-part of” relationship.

The aggregation association represents the part-whole relation between classes.Denoted by a solid diamond and linesDiamond attaches to the aggregate (whole) while lines attach to the partsMay have all association adornments

Whole Part

Car Door House

Page 15: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

23

Aggregation (cont.)

Aggregation tests: Is the phrase “part of” used to describe the relationship?

A door is “part of” a carAre some operations on the whole automatically applied to its

parts? Move the car, move the door.

Are some attribute values propagated from the whole to all or some of its parts? The car is blue, therefore the door is blue. A door is part of a car. A car is not part of a door.

Car Door House

Whole Part

Page 16: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Aggregation

*Pizza Order

Slice

Crust

Sauce Serving

Cheese Serving

Topping Serving

Page 17: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

25

CompositionComposition is a form of aggregation with strong

ownership and coincident lifetime of the parts by the whole; the part object may belong to only one whole – the parts are usually expected to live and die with the whole. (usually, any deletion of the whole is considered to cascade to the parts}{filled diamond}

Page 18: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Aggregation and Composition

Aggregation is a special form of association that specifies a whole-part relationship between the aggregate (the whole) and a component (the part); aggregation is the part-of relationship. { it is a special form of association in which a collection of objects, each having an independent existence, is associated with an single object} {unfilled diamond}

Composition is a form of aggregation with strong ownership and coincident lifetime of the parts by the whole; the part object may belong to only one whole – the parts are usually expected to live and die with the whole. (usually, any deletion of the whole is considered to cascade to the parts}{filled diamond}

Page 19: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration
Page 20: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration
Page 21: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Metadata

The term "meta" comes from a Greek word that denotes something of a higher or more fundamental nature. Metadata, then, is data about other data.

The term refers to any data used to aid the identification, description and location of networked electronic resources

Page 22: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Defining Metadata

Librarians equate it with a complete bibliographic record

Information technologists equate it to database schema or definitions of the data elements

Archivists include context information, restrictions and access terms, index terms, etc.

Page 23: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Metadata

Metadata is data that describes other data. For example, a class definition is a metadata.

Models are inherently metadata, since they describe the things being modeled (rather than being the things).

Many real-world applications have metadata, such as parts catalogs, blueprints, and dictionaries. Computer-languages implementations also use metadata heavily.

Page 24: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Derived Data

A derived element is a function of one or more elements, which in turn may be derived.

A derived element is redundant, because the other elements completely determine it.

Ultimately, the derivation tree terminates with base elements. Classes, associations, and attributes may be derived. The notation for a derived element is a slash in front of the element

name along with constraint that determines the derivation.

Page 25: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Derived Data

Employee

Basic Pay

/gross pay

Page 26: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Packages

A package is a group of elements (classes, association, generalization, and lesser packages) with a common theme.

A package partitions a model making it easier to understand and manage. Large applications my require several tiers of packages.

Packages form a tree with increasing abstraction toward the root, which is the application, the top-level package.

Notation for package is a box with a tab.

Page 27: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

Customer Order

Sales

Page 28: Enumerations Multiplicity Scope Visibility · Enumeration Data type - a set of values together with a set of operations on those values To define a new simple data type, called enumeration

When to use Package

To create a overview of a large set of model elements

To organize a large model

To group related elements