CSC186 - 1) Introduction To OOP
CSC186 - 1) Introduction To OOP
OBJECT ORIENTED
PROGRAMMING
Topic 1:
Introduction to OOP
Topic Covered
Programming basics
Introduction to objects & classes
Elements of an object - attribute, behavior,
state
Characteristics of OOP - abstraction (basic
concept, process abstraction, data abstraction),
encapsulation, inheritance, polymorphism
STRUCTURED
PROGRAMMING APPROACH
Structured Programming Approach
◦ Is a method that involves the use of objects and their relationships in order to
describe, programmatically, the problem to be solved.
• Easier debugging
◦classes can be tested independently
◦reused objects have already been tested
8
INTRODUCTION TO OBJECTS
Introduction to Object
◦ Objects are key to understanding object-oriented
technology.
◦ In real life, things that you see such as cars, trees, cats,
mobile phones and so on are objects. Even, you as a
student is an object.
Object can be
called and used as
Behavior single unit
Properties used to
defined
characteristics of Attribute /
the object Identity
State
OBJEC
T
OBJECT-ORIENTED
PROGRAMMING TERMS
Class & Objects
class
- a category of similar objects (a group)
- does not hold any values of the object’s attributes
object
- usually a person, place or thing (a noun)
attribute
- description of objects in a class (a characteristic)
method
- an action performed by an object (a verb)
Class & Objects
◦ Each object has:
◦ Attribute/Field - descriptive characteristics
◦ Behavior/Method - what it can do (or what can be done
to it)
E.g:
◦ The attribute of a bank account includes its account number and its current
balance
◦ The behaviors associated with a bank account include the ability to make
deposits and withdrawals
Example for attributes and methods
Attributes Methods
Methods
stud : Student • Represents the behaviors.
name=“Orked” • A sequence of instructions that a class or an object
id=“1234” follows to perform a task.
+setName()
+setId() object / instance of the class
Class Object
a kind of template. a thing, both tangible and
represents the intangible.
common structure is comprised of data &
behavior shared by operations that
the same type. manipulate these data.
a collection of is called an instance of a
objects of similar class.
type.
must be defined
before creating an
instance of the class.
Test Yourself
Dreamer Dance Class is an institution that conducts
dance classes for its clients. The institution would
like to upgrade their client registration system. For
each client registered, the new programs will store
client's name, address and phone number; the name
of dance classes in which the client is enrolled.
Among the information given, identify the object
and the attributes for the system.
CHARACTERISTICS OF OOP
Characteristics/concepts of OOP
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
ABSTRACTION
ABSTRACTION
◦ Focus only on the important facts about the
problem at hand
Analogy:
26
ENCAPSULATION
◦ Data hiding - Provides a way to protect your data from the outside world.
ENCAPSULATION
Analogy:
◦ A subclass has at least one attribute/method that differs from its superclass
◦ Other names :
◦ base class-derived class
◦ parent class-child class
INHERITANCE
Superclass
Vehicle
Subclasses
What properties does each vehicle inherit from the types of vehicles above it
in the diagram?
32
Example : mobile phone
CameraPhone
model
manufacturer
price
pixel PdaPhone
MobilePhone
… model
model
manufacturer manufacturer
price subclass price
memoryCap
… …
superclass subclass
INHERITANCE
Analogy:
E.g:
This class has 2 methods with the same name but with different type of parameters
POLYMORPHISM
Analogy:
Thank you.