OOP And UML
Summary
- Introduction
- Objects and Classes
- Why use OO?
- Object Oriented Analysis and Design
- Running Example
- Structural Diagrams
- Behavioral Diagrams
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
- 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
- Data
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 requirements
- Four step process
- Obtain/Prepare textual description of problem
- Underline nouns classes
- Underline adjectives attributes
- Underline active verbs operations
Running Example
Course Management System
- The Registration Manager sets up the curriculum for a semester using a scheduling algorithm
- One course may have multiple course offerings
- Each course offering has a number, location, and time
- Students select 4 primary courses and 2 alternative courses by submitting a registration form
- Students may use the system to add/drop courses for a period of time after registration
- Professors use the system to receive course offering rosters
- Users of the registration system are assigned passwords which are used at logon validation
UML from ChatGPT (NOTE: THIS IS INCORRECT)
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
Initial class diagram
Attributes
Represent the structure of a class
May be found by:
- Examining class definitions
- Studying requirements
- Applying domain knowledge
Operations
Represent the behavior of a class
May be found by examining interactions among entities
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
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
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