Reaves.dev

v0.1.0

built using

Phoenix v1.7.12

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

History

James Rumbaugh

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

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
1
1..*
has
1
1..*
has roster
1
0..*
selects primary
0..*
4
selects alternative
0..*
2
uses
assigns
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:

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:

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

Edge = Relationship

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

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

Documenting Use Cases

The behavior of use cases can be specified by describing its 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

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