0% found this document useful (0 votes)
95 views21 pages

SWE 320 Object Oriented Programming (OOP) : College of Technological Innovations (Cti)

This document discusses object-oriented programming concepts like classes, objects, encapsulation, and relationships between classes. It focuses on UML class diagrams, which show classes, attributes, methods, and relationships. Relationships include association, aggregation, composition, and inheritance. Association represents a "has-a" relationship, aggregation a "part-of" relationship, composition where the part depends on the whole, and inheritance an "is-a" relationship between a parent and child class. Examples are provided to illustrate class diagrams and different types of relationships.

Uploaded by

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

SWE 320 Object Oriented Programming (OOP) : College of Technological Innovations (Cti)

This document discusses object-oriented programming concepts like classes, objects, encapsulation, and relationships between classes. It focuses on UML class diagrams, which show classes, attributes, methods, and relationships. Relationships include association, aggregation, composition, and inheritance. Association represents a "has-a" relationship, aggregation a "part-of" relationship, composition where the part depends on the whole, and inheritance an "is-a" relationship between a parent and child class. Examples are provided to illustrate class diagrams and different types of relationships.

Uploaded by

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

SWE 320

Object Oriented Programming


(OOP)
COLLEGE OF TECHNOLOGICAL INNOVATIONS (CTI)
Topics of Discussion
• Recap!

• UML Class Diagrams

• Class Relationship
• Association
• Aggregation
• Composition
• Inheritance
Recap …
• OOP helps to reduce software complexity and makes it easier to create
software components closer to real-world entities.
• OOP builds software bottom-up by integrating objects.
• Classes bundles data and functionality together. A new class creates a
new type, allowing new instances (objects) of that type to be made.
• Objects are defined by attributes/data and behavior/functions/methods.
• The values of the Attributes or Data defines the state of the Object.
• The object’s state is changed by the behaviors/methods.
• Encapsulation/Information Hiding, and Abstraction
• Represent real-world objects as software objects.
• Reduce complexity by only considering essential characteristics.
Class Diagrams
Unified Modelling Language - UML
UML Class Diagrams
• Unified Modeling Language (UML) Class Diagram is a set of notations
that describe the structure of a system by showing the system's
classes, their attributes, functions (or methods), and the relationships
among the objects.
ML ET
sta ll U
In
The Class
• Class diagram is composed of three parts:
• Top Section - Name of the class
• This section is always required.
• The name is centralized in the section
• Middle Section - Attributes of the class
• The attributes describe the variables that
describe the qualities of the class.
• Bottom section - Functions of the class
• The methods are listed where each
operation takes up its own line.
• The operations describe how a class can
interact with data.
Class Member Visibility
• Visibility markers signify the access of information within a Marker Visibility
class. - Private
+ Public
• Private visibility, denoted with a - sign, hides information
# Protected
from anything outside the class.
~ Package
• Public visibility, denoted with a + sign, allows all other
classes to view the marked information.
• Protected visibility, denoted with a # sign, allows child
classes to access information they inherited from a parent
class.
• Package visibility, denoted by a ~ sign, allows class
information to be accessed by all classes within a package.
Class Relationships
• Like in the real-world, software objects can also be related to each other.
• An Apple is a Fruit
• A Passenger has a Boarding Pass for a Flight
• A Student studies a Course offered by a Department in a University
• It is important to represent these relationships when designing software.

• UML Class Diagrams also include notations to represent relationship between classes.

• We consider the following relationships between classes:


• Association – “has-a”
• Types of Association
• Aggregation
• Composition
• Inheritance – “is-a”
Association
• An Association is a broad term that indicates any logical dependency
or relationship between classes.

• Associations are represented by a straight line between two classes.


The line indicates that both classes are related to each other i.e.
Binary Association.
• An association is commonly referred to as a “has-a” relationship.
• Sometimes a label is added to the line to give more clarity to the
relationship
Multiplicity
• Associations are also defined with
Multiplicity or Cardinality
• Multiplicity/Cardinality options are
• 0..1 – Class A maybe related to a maximum of Considering an attendance
one instance of the Class B software, the above class
• n – Class A is related to exactly n instance of relation would mean:
the Class B
• 1..* – Class A is related to at-least one A classroom has 0 or more
instance of the Class B students and a student is in
• * – Class A maybe related to many instances 0 or 1 classroom at a given
of the Class B point in time.
• n..m – n instances of Class A is related to m
instances of the Class B
Binary Association
• A classroom has
many students
• A student can be
in a maximum of
1 class at a time

• Note:
• Classroom class – includes List of students with the setter and getter methods
• Student class - includes Instance of Classroom class with the setter and getter
methods
Unary Association
• Association can be directional, and this is indicated with a single line
and an arrowhead.
• The relation is only in one direction
• This is also called “Unary Association”
• Example: A Person has an Address

• The arrow indicates the direction of relationship.


• A Person has an Address
• The Address does NOT know the person
Association

• In the Unary Association, one class


contains the other.
• Note: Person class has an instance of the
Address class as one of its attributes.
Class Activity
• Consider a software that manages air travel.
• A passenger is allowed into a flight only if she/he has a “Boarding
Pass”
• Draw the Class Diagram to represent the “Boarding Pass” and a
“Passenger”
• Identify necessary data and methods.
• Include the relationship and cardinality between the two classes.
• Include extra method to find the remaining time to board
Aggregation
• Aggregation is a type of association.
• Aggregation defines a whole-part relationship. Also called “part-of”
relationship
• The notation is a line with a hollow diamond close to the whole-class.
• Example: A team has many players or the player is part-of a team
Composition
• Composition is also a type of association.
• Composition defines a whole-part relationship.
• Unlike the Aggregation relationship, in Composition the existence of
the part-class depends on the existence of the whole-class
• Construction and destruction of the part-class depends on the whole-class
• The notation is a filled diamond near the whole-class.
• Example: A department is part of a University
Inheritance
• This relationship defines the ability of one class (sub/child) to inherit the
functionality of another class (super/parent).
• Inheritance is also called the “is-a” relationship
• The notation is a solid line with a closed, unfilled, arrowhead pointing at
the super class

• For example:
• Car is a Vehicle
• Bicycle is a Vehicle

• The sub classes share common attributes and behavior of the super class
Class Activity
• Can you read the UML class diagram?
• Identify the classes, attributes, behavior, and relationships of the class
diagram represented below.
Class Activity
• Design a software to manage the sales of items in a shop. The shop
sells two items, books and CDs. For each item sold the software has to
track the details like id, title, description, author(s)/producer(s), date
sold, and price. Your software should be able to indicate the remaining
stock of items in the shop and also give the total cost of the remaining
items in the shop.

• Identify the classes, the related data, and functions.


• Draw the class diagrams with the data and functions.
• Ensure to represent the relationship between the classes.
Class Activity
• An airline company employs many employees. The company assigns
employees (e.g. pilots, flight attendants) to flights. A flight is assigned
an airplane. Passengers buy tickets to get on a flight and they also
choose a seat on the airplane. They have a right to cancel their tickets
a day before the departure time of the flight.

• Identify the classes, the related data, and functions.


• Draw the class diagrams with the data and functions.
• Ensure to represent the relationship between the classes.
In Summary
• UML Class Diagrams

• Class Relationship
• Association – has-a relation
• Aggregation is part-of relation and is a type of Association
• Composition is also a type of Association
• Inheritance – parent and child class

You might also like