SWE 320 Object Oriented Programming (OOP) : College of Technological Innovations (Cti)
SWE 320 Object Oriented Programming (OOP) : College of Technological Innovations (Cti)
• 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.
• 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
• 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.
• 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