




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Lecture 5
2
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
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
5
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
n Object is a thing that has behavior, state and identity
10
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
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
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
n Objects accept messages advertised in their interfaces
n Objects send messages to other objects
14
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
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
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
21
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
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
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