introduction to oop chapter 1 csc238 1. objectives 2 at the end of this topic, you should be able to...
TRANSCRIPT
![Page 1: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/1.jpg)
INTRODUCTION TO OOP
Chapter 1
CSC238 1
![Page 2: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/2.jpg)
Objectives2
At the end of this topic, you should be able to know the elements of an object. differentiate between objects and classes. understand the characteristics of OOP.
NH2008
![Page 3: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/3.jpg)
Object3
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.
Each object has states , behaviours and identity.
NH2008
![Page 4: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/4.jpg)
NH2008
4
OBJECT
Attribute /state – properties used to define characteristics.
Behaviour – means the object can perform actions & can have actions performed on it.
Identity – means the object can be called & used as a single unit.
Elements of an Object
![Page 5: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/5.jpg)
Example 1:
State :
Turn on
Current temperature is at 20 degree celcius
Behaviours :
Change the temperature level
5
NH2008
An air-conditioner at MK02
![Page 6: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/6.jpg)
Example 2:
State :
Dark brown colours on its face, ears and feet
Behaviours :
Playing, fighting, hunting
6
NH2008
A Siamese Cat
![Page 7: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/7.jpg)
Example 3:
They are 3 different cats which two of them are of the same type.
What makes them different?
their states , behaviours and identity.
7
NH2008
How about the following cats?
![Page 8: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/8.jpg)
Example 4:8
NH2008
Different types of cats Share the same behaviours
![Page 9: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/9.jpg)
Example 5:
Try to identify their common attributes and behaviours .
9
NH2008
How about these cars?
![Page 10: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/10.jpg)
Lesson Learned…10
What can you tell from example 3 to 5? A group of animals or things that are similar in some way. They share the same attributes and behaviours. This group of objects represents a class.
NH2008
![Page 11: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/11.jpg)
● a kind of template.● represents the common
structure & behaviour shared by the same type.
● A collection of objects of similar type.
● must be defined before creating an instance of the class.
● a thing, both tangible and intangible.
● is comprised of data & operations that manipulate these data.
● is called an instance of a class.
11
NH2008
Class Object
Class ? Object ?
![Page 12: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/12.jpg)
Example 6:12
● Represents the data/ attributes variables.
● a set of properties
Methods
Variables
• Represents the behaviours.• A sequence of instructions that a class
or an object follows to perform a task.
Student
nameid
setName()setId()
: Student
name=“Sarah”id=“1234”
class
object / instance of the class
NH2008
![Page 13: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/13.jpg)
Messages13
● An object can’t exist on its own.● An object communicates with other objects.● Therefore, a message is used to instruct a class or an object to
perform a task.● An object or a class only responds to messages that it can
understand. Messages must match the method that it possess. ● A list of messages is called an interface.
NH2008
![Page 14: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/14.jpg)
14
Abstraction Encapsulation Inheritance Polymorphism
NH2008
Characteristics of OOP
![Page 15: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/15.jpg)
Characteristic of OOP
● the act of representing essential features without including the background details or explanations.
● Use to manage complexity● Abstraction can be managed
through the use of hierarchical classifications.
● The mechanism that binds together code and the data it manipulates and keeps both safe from the outside interference and misuse.
● Access to the code & data inside the wrapper is tightly controlled through a well-defined interface.
15
NH2008
Abstraction Encapsulation
![Page 16: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/16.jpg)
16
NH2008
Student
Variables:name student idaddresscourse
Methods:changeAddress(String)changeCourse(String)
INTERFACEchangeAddress(String)changeCourse(String)
Example 7:
![Page 17: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/17.jpg)
● The process by which one object acquires the properties of another object.
● An object need only to define all those qualities that make it unique within its class. It inherits its general attributes from its parent.
● A subclass has at least one attribute/method that differs from its superclass
● Other names :base class-derived class, parent class-child class
17
NH2008
Inheritance
Characteristics of OOP
![Page 18: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/18.jpg)
18
Mobile Phone
NH2008
MobilePhone
modelmanufacturerprice
…
CameraPhone
modelmanufacturerpricepixel
…
superclass subclass
subclass
PdaPhone
modelmanufacturerpricememoryCap
…
Example 8:
![Page 19: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/19.jpg)
Characteristics of OOP
● From the Greek, meaning “many forms”.● A feature that allows one interface to be used for a general class of
actions.● “one interface, multiple methods”● Can be applied in the overloaded methods (a few methods that
have the same name but with different parameters).
19
NH2008
Polymorphism
![Page 20: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/20.jpg)
20
● Class : Rectangle● Variables : length, width, height● Methods : ….
displayShape(char simbol) displayShape(int a)
This class has 2 methods with the same name but with different type of parameters
NH2008
Example 9:
![Page 21: INTRODUCTION TO OOP Chapter 1 CSC238 1. Objectives 2 At the end of this topic, you should be able to know the elements of an object. differentiate](https://reader036.vdocument.in/reader036/viewer/2022062304/56649d9c5503460f94a844f9/html5/thumbnails/21.jpg)
21
● Elements of an object are attribute, behaviour and identity.● A class is a collection of objects of similar type.● An object is comprised of data and operations that manipulate
these data.● Characteristics of OOP is abstraction, encapsulation, inheritance
and polymorphism.
NH2008
Conclusion