0% found this document useful (0 votes)
8 views26 pages

OOAD With Examples

Uploaded by

oluochlawrence31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views26 pages

OOAD With Examples

Uploaded by

oluochlawrence31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Encapsulation

 Hide implementation from clients


◦ Clients depend on interface

How does an object encapsulate?


What does it encapsulate?

Improves Resiliency
Modularity
 The breaking up of something complex
into manageable pieces Order
Entry

Order Processing
System Order
Fulfillment

Billing

Manages Complexity
Hierarchy Asset
Increasing
abstraction
 Levels of abstraction

BankAccount Security RealEstate

Savings Checking Stock Bond

Decreasing Elements at the same level of the hierarchy


abstraction should be at the same level of abstraction
Object
 Informally, an object represents an entity,
either physical, conceptual, or software
◦ Physical entity
Truck

◦ Conceptual entity
Chemical Process

Linked List

◦ Software entity
Representing Objects
 An object is represented as rectangles
with underlined names
: Professor
a + b = 10

ProfessorClark
Class Name Only
Professor Clark
ProfessorClark :
Professor Object Name Only

Class and Object Name


Sample Class
Class
Course
Properties Behavior
Name Add a student
Location Delete a student
a + b = 10
Days offered Get course roster
Credit hours Determine if it is full
Start time
End time
Representing Classes
 A class is represented using a rectangle
that is then divided into sections

a + b = 10
Professor

Professor Clark
Class Compartments
 A class is comprised of three sections
◦ The first section contains the class name
◦ The second section shows the structure
(attributes or variables)
◦ The third section shows the behavior
(operations)
Class Name Professor
name
Attributes empID
Operations create( )
save( )
delete( )
change( )
The Relationship Between Classes
and Objects
 A class is an abstract definition of an
object
◦ It defines the structure and behavior of each
object in the class
◦ ItObjects
serves as a template for creating objects
Class

 Objects are grouped into classes


Professor

Professor Smith Professor Mellon

Professor Jones
Attribute
Object
Class

Attribute Attribute Value


:CourseOffering
number = 101
startTime = 900
CourseOffering endTime = 1100
number
startTime
endTime :CourseOffering
number = 104
startTime = 1300
endTime = 1500
Operation

CourseOffering
Class
addStudent
deleteStudent
getStartTime
Operation getEndTime
Polymorphism
 The ability to hide many different
implementations behind a single interface

Manufacturer B
Manufacturer A Manufacturer C

OO Principle:
Encapsulation
Interface
 Interfaces formalize polymorphism
 Interfaces support “plug-and-play”
architectures Tube
<<interface>>
Shape
Pyramid
Draw
Move
Scale
Rotate Cube

Realization relationship (stay tuned for realization relationships)


Component
 A non-trivial, nearly independent, and
replaceable part of a system that fulfills a
clear function in the context of a well-
defined architecture
OO Principle:
 A component may be Encapsulation
◦ A source code component
◦ A run time components or
◦ An executable
Source File component
<<EXE>> <<DLL>>
Name Executable Component
Name Component Name
Interface
Package
 A package is a general purpose mechanism
for organizing elements into groups
 A model element which can contain other
model elements

OO Principle:
Package Name Modularity

 Uses
◦ Organize the model under development
◦ A unit of configuration management
Relationships
 Association
◦ Aggregation
◦ Composition
 Dependency
 Generalization
 Realization
Relationships: Association
 Models a semantic connection among
classes
Association Name

Professor Works for University

Association
Role Names

Class University
Professor
Employee Employer
Relationships: Aggregation
 A special form of association that models
a whole-part relationship between an
Whole aggregate (the whole) and its parts Part

Student Schedule

Aggregation
Relationships: Composition
 A form of aggregation with strong
ownership and coincident lifetimes
Whole ◦ The parts cannot survive the whole/aggregate
Part

Student Schedule

Aggregation
Association: Multiplicity and
Navigation
 Multiplicity defines how many objects
participate in a relationships
◦ The number of instances of one class related to
ONE instance of the other class
◦ Specified for each end of the association
 Associations and aggregations are bi-
directional by default, but it is often desirable
to restrict navigation to one direction
◦ If navigation is restricted, an arrowhead is added
to indicate the direction of the navigation
Association: Multiplicity
 Unspecified 1
 Exactly one 0..*
 Zero or more (many, unlimited)
*

1..*

 One or more 0..1

 Zero or one 2..4

 Specified range 2, 4..6

 Multiple, disjoint ranges


Example: Multiplicity and Navigation

Multiplicity

Student 1 0..* Schedule

Navigation
Relationships: Dependency
 A relationship between two model
elements where a change in one may
cause a change in the other
Class
Non-structural, “using”
Client Supplier relationship
Component

Package Client Supplier


Dependency
relationship

ClientPackage SupplierPackage
Dependency
relationship
Relationships: Generalization
 A relationship among classes where one
class shares the structure and/or behavior
of one or more classes
 Defines a hierarchy of abstractions in
which a subclass inherits from one or
more superclasses
◦ Single inheritance
◦ Multiple inheritance
 Generalization is an “is-a-kind of”
relationship
Example: Single Inheritance
 One class Ancestor
inherits from another
Account
balance
name
Superclass number
(parent) Withdraw()
CreateStatement()
Generalization
Relationship

Checking Savings

Subclasses Withdraw() GetInterest()


Withdraw()

Descendents
Example: Multiple Inheritance
 A class can inherit from several other
classes
FlyingThing Animal

multiple
inheritance

Airplane Helicopter Bird Wolf Horse

Use multiple inheritance only when needed, and


always with caution !

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy