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

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

This document discusses object-oriented programming and managing software complexity using OOP concepts. It defines key OOP concepts like classes, objects, attributes, behaviors, encapsulation, and abstraction. An example class named "Car" is used to demonstrate how it would have attributes like manufacturer, model etc. and behaviors like getting/setting attributes and actions like accelerating. The document emphasizes that OOP helps in modeling complex real-world systems and managing changing requirements through its bottom-up approach.

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)
85 views21 pages

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

This document discusses object-oriented programming and managing software complexity using OOP concepts. It defines key OOP concepts like classes, objects, attributes, behaviors, encapsulation, and abstraction. An example class named "Car" is used to demonstrate how it would have attributes like manufacturer, model etc. and behaviors like getting/setting attributes and actions like accelerating. The document emphasizes that OOP helps in modeling complex real-world systems and managing changing requirements through its bottom-up approach.

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
• The Object Oriented Paradigm
• Managing Software Complexity
• The Object and its Class
• Attributes and Behaviors
• Encapsulation & Information Hiding
• Abstraction
The Object Oriented Paradigm
Encapsulation & Abstraction
Software Complexity
• Real-World systems are becoming more and more reliant on software.
• Ex: Banking, Transportation, Navigation, Health Care, Education, Security etc.

• 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

• The impact of reducing software complexity is paramount in terms of cost


and also reducing the effort of building software.

• Many times, even life saving, because these software control real-world
systems.
Understanding
Requirements
• The challenge of Requirement
Elicitation.

• How to reduce the impact of


change on software?

• How to connect the


requirements to the actual
implementation?

• How to ensure scalability?


Good Model Reduces Software Complexity
• A major reason for software complexity is the difficulty in
understanding the software model which represents a software
system [1].
• Having a good software model helps to translate ideas
(requirements) into working programs (software)
• It also helps to easily change/update software based on new
requirements
• A model that is easy to understand is also easier to use and
maintain, which reduces the likelihood of introducing errors when
creating or updating it.
Managing Software Complexity
• An unambiguous representation (modelling notation and programing
language) with precise semantics eases software creation.
• For this course we use,
• UML Class Diagrams as a notation to model ideas and requirements
• Python programming language to create working programs/software

• The approach to building software can be either:


• Top-Down: The “Divide and Rule” or “Algorithmic Decomposition” concept
looks at breaking down requirements into smaller functions.
• Bottom-Up: The approach pieces together smaller units to give rise to the
larger systems. In a bottom-up approach the smaller parts of the system are
first specified in great detail.
Object Oriented Programming (OOP)
• Complex scenarios are easily modelled and programmed
using Object Oriented (OO) concepts
• Object Oriented Programing (OOP) uses the Bottom-Up approach.

• In OOP, small independent units of the software known as


Objects are first created.
• Objects are the building blocks of the software

• A program or software is created by the collection of


interacting Objects.

• Examples of OOP Languages: C++, Python, Java, Smalltalk, C#


The Object and its Class
• A Class is the template of an object. It is used to model objects for
implementing a software
• Example: Student, Musical instrument, Fruit, Car

• An Object in a software context, is a uniquely identifiable representation of a


real-world entity. It has attributes and behaviors
• Example: Samir, Guitar, Apple, Toyota Camry

• An Object is an instance of a Class


• Samir is an instance of a Student
• A guitar is an instance of a Musical instrument
• An apple is an instance of a Fruit
• A Toyota Camry is an instance of a Car
Attributes and Behaviors
• Consider a car, a real-world entity that needs to be represented in a software.
• Let’s say the car is, a 2017 model Toyota Camry
• For our software let’s call the car, myCar
• Therefore, myCar is a software object that identifies my real-world car

• To use it in a software, we define a class that would represent myCar.


• Let’s call the class, Car
• Therefore, myCar is an instance of Car

• 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

• The state myCar is determined by the changes to the attributes.


• The value of the attributes are modified using the behaviors of the object
Class Activity
• Students can work in groups.

• Discuss and write the attributes of the class: Student


• Identify at-least 20 attributes
• Include the data types that represent the attributes
• Use proper notations, e.g.
• name: string,
• age: int

• Consider zuStudent to be an object of the above class


Class Behaviors
• A behavior is an action that retrieves or changes the state of an object.
• A behavior provides the means for interaction with the object
• A behavior is also called a function or method.
• Example: Some behaviors of myCar
• getManufacturer() returns an enum
• getNumberOfDoors() returns an int
• getEngineState() returns a Boolean
• getCurrentSpeed() returns a float

• setEngineState(Boolean) starts myCar


• setCurrentSpeed(float) sets the speed of myCar to 45 Km/Hr.
• setColor(enum) sets the color of myCar to Black
Behavior, Functions, or Methods
• Other than the setter and getter methods, the object will also have
other functions, to represent real-world actions.
• Example, for myCar, we could have functions like:
• checkRemainDistance(float, float): float
• Calculate remaining distance based on remaining fuel, and current speed. The function
returns the distance which is a float value
• turnLeft(float) : Boolean
• the car turns left at a certain angle, and the function returns True or False
• turnRight(float) : Boolean
• the car turns right at a certain angle, and the function returns True or False
• stopCar() : Boolean
• the car stops and the function returns True or False
• accelerate(float) : Boolean
• the car increases speed at a certain value, and returns True or False
Class Activity
• Students can work in groups.

• Discuss and write down the behaviors of the class: Student


• For all the attributes identified earlier, write down the associated setter
methods (mutator) and getter methods (accessor)
• Include the data types that represent the attributes
• Use proper notations

• Consider zuStudent to be an object of the above class


Encapsulation
• An object encapsulates the get
r() Eng
attributes, behaviors, and the set
Co lo ine
S tate
state of a real-world entity. ()

setC
)
Manufacturer

or(
• The state of an object Toyota

Col

urre
represented by the attributes

get

ntSp
Gears Model

or data are hidden inside the 5 Camry

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.

• Abstraction simplifies the understanding and use of complex systems


by hiding information that is not relevant to context of the software.
• It reduces complexity and increases efficiency

• 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

You might also like