0% found this document useful (0 votes)
50 views

CS 103 Computer Programming: Week 02

This document discusses object-oriented programming concepts like classes, objects, and the relationship between them. It defines a class as a blueprint or template for objects, and an object as an instance of a class. Classes contain attributes and behaviors that their object instances will have. The document uses examples like a bicycle class and individual bicycle objects to illustrate the differences between classes and objects. It also covers concepts like generalization and specialization of classes.

Uploaded by

syed02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

CS 103 Computer Programming: Week 02

This document discusses object-oriented programming concepts like classes, objects, and the relationship between them. It defines a class as a blueprint or template for objects, and an object as an instance of a class. Classes contain attributes and behaviors that their object instances will have. The document uses examples like a bicycle class and individual bicycle objects to illustrate the differences between classes and objects. It also covers concepts like generalization and specialization of classes.

Uploaded by

syed02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

1/30/2018

CS 103 Computer Programming


Spring 2018

By Faiza Sattar
[email protected]

Week 02
•Basic Pillars of OOP
•Objects & Classes
•Abstraction
•Encapsulation
•Structures vs Classes

1
1/30/2018

Lecture 04

• Objects and Classes

Basic Pillars of OOP


• Abstraction
• Encapsulation
• Inheritance
• Polymorphism

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

Classify tangible or intangible objects


• Cup
• BankAccount
• Time
• Desk
• Fan
• TeamPlayer
• Date

Object-Oriented Programming
An object is anything that can be represented by data.

4
1/30/2018

Defining an Object

An object is a self-contained entity


with attributes and behaviors

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

• Object belongs to a group.


• Which are similar.
• Have some common attributes.
• Have some common behaviors.
• We can categorized objects on some
basic features …. ?

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.

Instance and Instantiation


• Each copy of an object from a particular class
is called an instance of the class.
• The act of creating a new instance of a class is
called instantiation.

11
1/30/2018

Classes & Objects

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()

Instances of a Class- Bicycle

Two different instances of


the same class will have the
same properties, but
different values stored in
those properties.

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.

NOTE: Classes are invisible, object are visible

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

Quiz coming next week

15

You might also like