Docsity

Understanding Object-Oriented Modeling: Class Diagrams & Relationships, Study notes of Computer Science

Partial preview of the text

Download Understanding Object-Oriented Modeling: Class Diagrams & Relationships and more Study notes Computer Science in PDF only on Docsity!

Object-Oriented Modeling: Class

Diagrams

Object

Class (“selection” description) Class (“derivation” description)

Instances

• Sometimes class and object are used to

mean the same thing (by mistake).

How do you find objects/classes?

Objects have state How to recognize attributes

  • Descriptive attributes
  • Naming Attributes
  • Referential Attributes

Objects have behavior: Recognizing.

UML Class Diagram

Class Name Class Name Attributes Operations

Attributes and Functions

Car speed direction

UML notation: navigability

Arrow on association indicates responsibilities: Employee must be able to say what customers it is associated with. Customer has no corresponding ability to indicate what sales rep it has.

Notes

• Navigability may be in one direction or

both.

• Unlabeled associations may mean

  • Unknown
  • Bidirectional

• Associations can be named using verb

phrases.

• Roles can be named using nouns.

Recursive Associations

Node

Shared Aggregation

Class A (^) Role A Class B Role B The diamond is open (not filled). This says “B is a part of A.” A is made of B’s. The B’s are part of A.

Example

Document Paragraph Sentence

  • Properties of the aggregate

propagate to the parts as well.

  • Unless there are common

properties of parts that can be

attached to the aggregate as a

whole there is little point in using

aggregation.

Composition Aggregation

Class A (^) Role A Class B Role B

Here the diamond is filled.

The part object may belong to only one whole.

The parts are expected to live and die with the whole.

If the whole is deleted, the parts go with it.

The composed class probably creates the aggregate.

Aggregation Example

Company 1 Division

Employee

1

Complete the diagrams below

Directory (^) File Characters Car Motor Tires

UML notation:

subtypes/generalization

Customer Corporate Customer Private Customer Every attribute of Customer is also an attribute of its subclasses.

Notes: Subtypes/Supertypes:

Inheritance

• Every subtype must have the “is a”

relationship with its supertype.

• These are also known as “parent class”

and “child class”.

• All attributes and methods of the parent

are also attributes and methods of the

child.

Reasons for using Inheritance Types of Inheritance

  • Extension:
    • MovingPoint inherits from Point and adds speed and direction
  • Restriction:
    • Circle inherits from Ellipse and provides different area and circumference calculations

What are the differences between

interfaces and abstract classes?

Packages

The package is java.awt.

The other classes and

packages are internal

to java.awt.

datatransfer event image java.awt java.awt

If no internals are

detailed, the package

name goes inside the

package box.