Reaves.dev

v0.1.0

built using

Phoenix v1.7.20

OOP And UML

Stephen M. Reaves

::

2023-09-17

Notes about Lesson 5 of CS-6300

Summary

Introduction

data over function

information hiding/encapsulation

inheritance

Objects and Classes

Computing unit oriented around the collection of state and instance variables. Also associated with a set of operations.

A class is a blueprint for an object. Objects are instances of classes.

Why use OO?

Reduce maintenance costs

Improve development process by favoring code/design reuse

Enforces good design

Object Oriented Analysis and Design

Model software as a group of interacting objects

  • OOA
    • Concentrates on modeling real world objects

History

James Rumbaugh

  • Object Modeling Technique
    • Data
      • Modeling was based on extended version of entity relationship diagrams to describe classes and inheritance
      • Called object model
    • Functions
      • Dataflow Diagrams (DFDs) were used to model the functional aspects of the system
      • Called functional model
    • Control
      • Represented dynamic aspects of a system by using state transition diagrams

OMT (plus contributions from Jacobson, and Booch) led to UML

OOA

Define a system first in terms of its data types (and their relationships), and functions/methods are secondary, and only defined wrt objects

Real world objects \Rightarrow requirements

  • Four step process
    1. Obtain/Prepare textual description of problem
    2. Underline nouns \Rightarrow classes
    3. Underline adjectives \Rightarrow attributes
    4. Underline active verbs \Rightarrow operations

Running Example

Course Management System

  1. The Registration Manager sets up the curriculum for a semester using a scheduling algorithm
  2. One course may have multiple course offerings
  3. Each course offering has a number, location, and time
  4. Students select 4 primary courses and 2 alternative courses by submitting a registration form
  5. Students may use the system to add/drop courses for a period of time after registration
  6. Professors use the system to receive course offering rosters
  7. Users of the registration system are assigned passwords which are used at logon validation

UML from ChatGPT (NOTE: THIS IS INCORRECT)

sets up

contains

has

has roster

selects primary

selects alternative

uses

assigns

1
1
1
0..*
0..*
1..*
1..*
0..*
4
2

RegistrationManager

+setupCurriculum(semester: Semester) : : void

Semester

+semesterNumber: int

+courses: Course[]

Course

+courseCode: string

+courseName: string

+courseOfferings: CourseOffering[]

+addCourseOffering(courseOffering: CourseOffering) : : void

CourseOffering

+offeringNumber: int

+location: string

+time: string

+roster: Student[]

+addStudent(student: Student) : : void

Student

+studentID: string

+name: string

+selectedCourses: Course[]

+alternativeCourses: Course[]

+submitRegistrationForm(primaryCourses: Course[], alternativeCourses: Course[]) : : void

+addCourse(course: Course) : : void

+dropCourse(course: Course) : : void

Professor

+professorID: string

+name: string

+receiveRoster(courseOffering: CourseOffering) : : void

User

+userID: string

+password: string

+validateLogin(username: string, password: string) : : bool

Structural Diagrams

Represent static characteristics of the system

Class Diagram

Static Structural overview of the system

Describes class structure and class relationships

Class

Rectangles in three parts

Top part is name, then attributes, then operations

Name should be singular noun with Capital letter

ClassName

+ attribute

- attribute: type = initial_value

+ operation(arg-list) : : result_type

Initial class diagram

RegistrationForm

RegistrationManager

SchedulingAlgorithm

Professor

Student

Course

CourseOffering

Attributes

Represent the structure of a class

May be found by:

  • Examining class definitions
  • Studying requirements
  • Applying domain knowledge

CourseOffering

number

location

time

Operations

Represent the behavior of a class

May be found by examining interactions among entities

RegistrationManager

addStudent(Course, Student)

Course

name

numberCredits

open()

addStudent(Student)

CourseOffering

number

location

time

open()

addStudent(Student)

RegistrationForm

Professor

name

tenureStatus

Student

name

major

SchedulingAlgorithm

Relationships

Describe interactions between objects

3 main types:

  • Dependencies
    • “X uses Y”
    • dashed arrow
  • Association/Aggregation
    • “X has a Y”
    • solid line, somtimes with diamond
  • Generalization
    • “X is a Y”
    • Solid line with big arrow

Registers for ->

2..*
1..50

RegistrationManager

addStudent(Course, Student)

Course

name

numberCredits

open()

addStudent(Student)

CourseOffering

number

location

time

open()

addStudent(Student)

RegistrationForm

Professor

tenureStatus

Student

major

SchedulingAlgorithm

RegistrationUser

name

Tips

Understand the problem

Choose good class names

Concentrate on the WHAT

Start with a simple diagram and iterate

Component Diagram

Static view of components and their relationships

Node = Component

  • set of classes with a well-defined interface

Edge = Relationship

  • “uses services of”

Can be used to represent an architecture

Deployment Diagrams

Static deployment view of a system

Physical allocation of components to computational units

Node = Computational Unit

Edge = Communication

Behavioral Diagrams

Have to do with the dynamic aspects of the system

Use Case

Describe the “outside view” of they system

  • Sequence of interactions of outside entities (actors) with the system
  • System actions that yields an observable result of value to the actors

Oval means use case

Stick figure means actor(with role)

$plantuml @startuml !theme sketchy

left to right direction actor Guest as g package Professional { actor Chef as c actor “Food Critic” as fc } package Restaurant { usecase “Eat Food” as UC1 usecase “Pay for Food” as UC2 usecase “Drink” as UC3 usecase “Review” as UC4 } fc –> UC4 g –> UC1 g –> UC2 g –> UC3

@enduml plantuml$

Actor

Entity (human or device) that plays a role in a system

  • Can play more than one role

Documenting Use Cases

The behavior of use cases can be specified by describing its flow of events

  • Start and End
  • Normal flow of events
  • Alternative flow of events
  • Exceptional flow of events

Sequence Diagrams

Interaction diagram that emphasizes the time ordering of messages

math 101 section 1math 101registration managerregistration formmath 101 section 1math 101registration managerregistration formStudentfill in info1submit2add course(studen_name, math 101)3are you open?4are you open?5ack6ack7add(student_name)8add(student_name)9added10added11added(student_name)12registered13Student

State Transition Diagram

For each relevant class

  • Possible states
  • Events that cause a transition from one state to another
  • Actions that result from a state change
GstartstartinitInitializationdo: intiazlize coursestart->initcancCanceled do: notify registered studentsinit->cancCancelopenopen entry: Register Studentinit->openAdd Student/set count = 1open->cancCancelopen->openAdd Student [count < 10]/ increment countclosedClosed do: finalize courseopen->closed[count = 10]closed->cancCancel