SWE 320 Object Oriented Programming (OOP) : College of Technological Innovations (Cti)
SWE 320 Object Oriented Programming (OOP) : College of Technological Innovations (Cti)
• For all real-world systems the software has become very complex and the
relative size has increased enormously.
• The need to manage software has become very critical to all areas of life
• Many times, even life saving, because these software control real-world
systems.
Understanding
Requirements
• The challenge of Requirement
Elicitation.
• The class Car will provide the template to define any car by defining:
• Attributes and Behaviors common to any Car
• So, we need to identify
• Attributes or data that define a car.
• Behaviors or functions that define a car
Class - Attributes
• Discuss: What are the attributes or data that define a car?
o Manufacturer
o Model
o Year of Manufacture
o Engine Capacity
o Number of Doors
o Color
o Gear (Automatic or Manual)
o Number of Gears
o Drive Position (Left or Right Hand Drive)
o Number of Seats
o Type of Fuel (Petrol, Diesel, Electric, Hybrid)
o Fuel Capacity
o Fuel Consumption
o Max Speed
o Engine State (On/Off)
o Current Speed
An Object – Instance of a Class
• An instance of the class Car is myCar
• myCar is an object that has at-least these attributes
o Manufacturer - [Toyota]
o Model - [Camry]
o Year of Manufacture - 2017
o Engine Capacity - 2.4
o Number of Doors - 4
o Color - [Blue]
o Gear - [Automatic]
o Number of Gears - 6
o Drive Position - [Right]
o Number of Seats - 3 + 2
o Type of Fuel - [Petrol]
o Fuel Capacity - 60.0
o Fuel Consumption - 10 (Km/L)
o Max Speed- 200 (Km/Hr)
o Engine State (On/Off) - Off
o Current Speed - 0
• What would be the data types of the attributes listed above?
Attributes of Class - Car
• manufacturer :enum • [Toyota]
• model : enum • [Camry]
• yearOfManufacture :Date • 2017
• bodyType : enum • [Sedan]
• engineNumber :String • AX1839930S8920
• engineCapacity :float • 2.4
• numberOfDoors :int •4
• color : enum • [White]
• gear : enum • [Automatic]
• numberOfGears :int •6
• drivePosition : enum • [Right]
• numberOfSeats :String • 3+2
• typeOfFuel : enum • [Petrol]
• fuelCapacity :float • 60.0
• fuelConsumption :String • 10 Km/L
• maxSpeed :float • 200
• engineState :Boolean • False (Off)
• currentSpeed :float • 0.0
State of an Object
• An object’s state is defined by the value of it’s attributes.
• For Example:
• The state of myCar changes depending on the following attributes:
• engineState :Boolean
• currentSpeed :float
• myCar could be in a state that the engine is On and speed is 0
• myCar could be in a state that the engine is On and speed is 40
• myCar could be in a state that the engine is Off and speed is 0
• myCar CANNOT be in a state that the engine is Off and speed is 40
setC
)
Manufacturer
or(
• The state of an object Toyota
Col
urre
represented by the attributes
get
ntSp
Gears Model
e
…
e d(
object and is accessible via Current Speed
)
Doors
the behaviors or functions. 45.5
get
()
4
ors
anM
Type of Fuel
Do
Color
No
Petrol
fac
White
get
• This concept is also
ture
r()
understood as Information getG r()
C a
Hiding. ea r() sto
p
Abstraction
• It is the concept of removing certain attributes from something in
order to reduce it to only essential characteristics.
• For example:
• The myCar object does not describe all the details of a real-world car.
• Functions like the engine’s working or the shifting of gears are not included.
• The object abstracts only those functions and attributes that are required for the context
of the software being built.
In Summary
• The Object Oriented (OO) Paradigm
• Managing Software Complexity
• The Object and its Class
• Attributes and Behaviors
• Encapsulation & Information Hiding
• Abstraction