Understanding Objects and Classes in Object-Oriented Programming (OOP) by Dr. Jamil Ahmed, Slides of Object Oriented Programming

This document, from dr. Jamil ahmed's lectures, provides an in-depth explanation of objects, their behavior, state, identity, and communication through messages. It also covers the concept of classes, their role in creating objects, and their purpose in ensuring a consistent object interface. Object-oriented programming (oop) is a fundamental programming paradigm, and this document serves as a valuable resource for understanding its core concepts.

Typology: Slides

2011/2012

Uploaded on 07/17/2012

banani
banani 🇮🇳

4.3

(3)

91 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Dr. Jamil Ahmed
OBJECT ORIENTATION
Lecture 5
2
Lecture Overview
nWhat is an object?
nHow do objects communicate?
nHow is an object’s interface defined
nWhat are classes?
nWhat is the purpose of classes?
3
An object can be:
na thing in the 'real world’
na model of reality
na tangible or visible thing
na thing to which action or thought can
be directed (intangible)
npassive - doing nothing until activated
e.g. like a switch
nactive - continually monitoring until
conditions change e.g. like a thermostat
docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Understanding Objects and Classes in Object-Oriented Programming (OOP) by Dr. Jamil Ahmed and more Slides Object Oriented Programming in PDF only on Docsity!

OBJECT ORIENTATION

Lecture 5

2

Lecture Overview

n What is an object?

n How do objects communicate?

n How is an object’s interface defined

n What are classes?

n What is the purpose of classes?

3

An object can be:

n a thing in the 'real world’

n a model of reality

n a tangible or visible thing

n a thing to which action or thought can be directed (intangible)

n passive - doing nothing until activated e.g. like a switch

n active - continually monitoring until conditions change e.g. like a thermostat

4

World of Objects

n An Object is a thing one can

interact with.

n Interaction with an object can be

done by sending it messages.

n Object will react on receiving

message(s).

5

Behavior, State and Identity

n The behavior of the object depends

upon the current internal state of the object.

n The internal state may change in

reaction to receiving the message.

n In order to send messages, an object is

usually addressed by its name which is the identity of the object.

6

Object Defined

n Object is a thing that has behavior, state and identity

10

Attributes

n Mutable : Their values can change n Immutable : Their values cannot change n Value of the attributes define the state of an object, NOT the attributes themselves n In OOL, the set of attributes cannot change during the life of the object , though the values of those attributes can change

11

Behavior

n The way an object reacts as a result of message sending

n An object can receive messages and act on them

n The set of messages that an object understands is normally fixed

n The resulting response to the message(s) (i.e. behavior or service) depends upon the current values of its attributes

12

Identity

n Identity: Name of the object.

n The values of attributes may change, but the object remains the same. The same object continues to exist.

13

Messages

n Objects accept messages advertised in their interfaces

n Objects send messages to other objects

14

Messages (2)

n Messages may contain arguments (parameters) to clarify the request e.g. n myCat catch: aMouse n myCat moveTo: saucerOfMilk at: highSpeed n myCustomer.changePhoneNo (01705844032) n myCustomer.changeAddress (“PO Nilore”, “Islamabad”, “Pakistan”, “45650)

15

Messages (3)

n When a message is sent to an object, the sender will not know what code will be executed by the receiver because the information is encapsulated.

n That’s why we say that sender is making “assumptions”.

n Encapsulation allows the objects to offer services independent of implementation.

19

Classes (Instantiating)

n Process of creating a new object of a class is called Instantiating the class, and the resulting object an instance of the class.

n That’s why the attributes (variables) belonging to an object are called instance variables.

n The values of attributes are set during the object creation process

20

The Object Factory

n As class has a direct role in the

creation of a new object

n Object Template + Creation

Process

n Therefore a class is often seen as

The Object Factory

21

Classes as Objects

n Most languages allow classes to act like objects – having attributes, behavior and identity

n Example: n Customer class may have an attribute numberOfInstances, which is incremented whenever a new customer is created n Customer class may send itself a message (to) getNumberOfCustomers()

22

The Purpose of Classes

n Classes serve two purposes:

n A convenient way of describing a collection of consistently behaving objects n Classes provide the convenience of storing only one copy of code representing the object’s behavior (though conceptually every object encapsulates its own behavior)

23

Summary

n Objects have state, behavior and identity

n Objects interact with each other by sending messages

n Interface defines a collection of messages that an object understands

n Classes describe a collection of objects

n A Class ensures a consistent object interface