CS 103 Computer Programming: Week 02
CS 103 Computer Programming: Week 02
By Faiza Sattar
[email protected]
Week 02
•Basic Pillars of OOP
•Objects & Classes
•Abstraction
•Encapsulation
•Structures vs Classes
1
1/30/2018
Lecture 04
2
1/30/2018
Everything is an Object
Object
Everything in thing world is an object.
In general we say :
“ Any tangible or intangible thing for
which we want to save Information”.
3
1/30/2018
Object-Oriented Programming
An object is anything that can be represented by data.
4
1/30/2018
Defining an Object
12
Some Examples
Female sandal
SHOES /
FOOTWARES
Casuals
Men sandal
Formal
Loafers Pumpies
5
1/30/2018
Humans
FISH
6
1/30/2018
BIRD
Animal
7
1/30/2018
Discussion
Shoe – An Object
Properties Behavior
• Size (a number) • Put on
• Width (C, D, EEEE, etc.) • Take off
• Style (Sneaker, High Heel, Golf, • Tie
etc.) • Lace
• Brand (Nike, etc.) • Polish
• Color (Black, etc.) • Buy
• Owner (Mine, yours, etc.) • Throw
• Put Away
8
1/30/2018
Your Turn
• Phone
• Humans
• Fish
• Bird
• Animals
• Fan
Object
• Technical Definition:
– “An Object is an Instance of a class”
– “An Object is the implementation of a class”
9
1/30/2018
Class
• A class is an abstraction of its
instances. It defines all the
attributes and methods that its
instances must also have.
Person
name
sex
age
tellSex()
tellAge()
22
Class
• Collection of Similar object.
– The objects that share some common features.
– It is the a design of an object.
– It is a detail of an object.
– It tell us what an object contains in it.
10
1/30/2018
Class
• Technical Definition:
– “ A class is blueprint of an object”
– “ A class is a template of an object”
– A class is a group of objects with the same properties and
the same behavior.
11
1/30/2018
Class Vs Instance-Example
• A class is like a recipe for red velvet cake.
• The recipe itself is not a cake.
• You can't eat the recipe (or at least wouldn't want
to).
• If you correctly do what the recipe tells you to do
(instantiate it) then you have an edible cake.
• That edible cake is an instance of the red velvet cake
class.
12
1/30/2018
Class Vs Object
• Class Bicycle: • Object: Ali’s Bicycle
Bicycle
Speed
Gear
ChangeGear()
SpeedUp()
ApplyBrake()
13
1/30/2018
Summarize
• A class :
– It’s a blue print .
– It’s a design or template.
An Object:
– Its an instance of a class.
– Implementation of a class.
Generalized Class
• The class that only exhibits the common features
of its objects.
• Examples:
– ANIMAL
– BIRDS
– HUMAN
– No object of generalized class is found.
14
1/30/2018
Specialized Class
• The class that exhibits different or unique
features (behaviors)
• ANIMAL (Generalized)
– Specialized: WILD
ANIMAL
PET
• Mammals
CAT CAT
• Cats
• Dog Lion Streat Cat Persian
Siamese
Review
15